Permalink
Browse files

Raising exception if fixture file can't be found

  • Loading branch information...
1 parent c8509d5 commit 1c970b83943acbb63ebad274a2881ae5f8515509 @pavlos pavlos committed with tenderlove Aug 11, 2010
Showing with 15 additions and 0 deletions.
  1. +4 −0 activerecord/lib/active_record/fixtures.rb
  2. +11 −0 activerecord/test/cases/fixtures_test.rb
@@ -24,6 +24,8 @@ class FixtureClassNotFound < StandardError #:nodoc:
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 @@ def read_fixture_files
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
@@ -153,6 +153,17 @@ def test_empty_yaml_fixture_with_a_comment_in_it
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")

0 comments on commit 1c970b8

Please sign in to comment.