From be7f6bfc01e66ae5bfc99016b20d1ac041b3ffa1 Mon Sep 17 00:00:00 2001 From: Paul Hieromnimon Date: Tue, 10 Aug 2010 19:09:24 -0700 Subject: [PATCH] Raising exception if fixture file can't be found --- activerecord/lib/active_record/fixtures.rb | 4 ++++ activerecord/test/cases/fixtures_test.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index e44102b..4e49e9f 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -24,6 +24,8 @@ else end end +class FixturesFileNotFound < StandardError; end + # Fixtures are a way of organizing data that you want to test against; in short, sample data. # # = Fixture formats @@ -696,6 +698,8 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) read_yaml_fixture_files elsif File.file?(csv_file_path) read_csv_fixture_files + else + raise FixturesFileNotFound, "Could not find #{yaml_file_path} or #{csv_file_path}" end end diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 93f8749..a8c1c04 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -153,6 +153,17 @@ class FixturesTest < ActiveRecord::TestCase assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', FIXTURES_ROOT + "/naked/yml/companies") end + def test_nonexistent_fixture_file + nonexistent_fixture_path = FIXTURES_ROOT + "/imnothere" + + #sanity check to make sure that this file never exists + assert Dir[nonexistent_fixture_path+"*"].empty? + + assert_raise(FixturesFileNotFound) do + Fixtures.new( Account.connection, "companies", 'Company', nonexistent_fixture_path) + end + end + def test_dirty_dirty_yaml_file assert_raise(Fixture::FormatError) do Fixtures.new( Account.connection, "courses", 'Course', FIXTURES_ROOT + "/naked/yml/courses") -- 1.7.1