Skip to content

Commit

Permalink
Raising exception if fixture file can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlos authored and tenderlove committed Aug 11, 2010
1 parent c8509d5 commit 1c970b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/fixtures.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/fixtures_test.rb
Expand Up @@ -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")
Expand Down

0 comments on commit 1c970b8

Please sign in to comment.