diff options
author | Paul Hieromnimon <paul.hieromnimon@gmail.com> | 2010-08-10 19:09:24 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-11 15:47:34 -0700 |
commit | 007c4da9ae3d5ad03a9eefd4dfccf9ca447715f1 (patch) | |
tree | 57955aa724aca4531155b777340971e2d9eae3d6 /activerecord | |
parent | 7de03ec765e3160f5331fc17c8d7d332fa679d62 (diff) | |
download | rails-007c4da9ae3d5ad03a9eefd4dfccf9ca447715f1.tar.gz rails-007c4da9ae3d5ad03a9eefd4dfccf9ca447715f1.tar.bz2 rails-007c4da9ae3d5ad03a9eefd4dfccf9ca447715f1.zip |
Raising exception if fixture file can't be found
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 4 | ||||
-rw-r--r-- | 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 e44102b538..4e49e9f720 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 93f8749255..a8c1c04f8b 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") |