Skip to content

Instantly share code, notes, and snippets.

@mathie
Created April 11, 2011 13:26
Show Gist options
  • Save mathie/913507 to your computer and use it in GitHub Desktop.
Save mathie/913507 to your computer and use it in GitHub Desktop.
If you've got to use fixtures, the least you can do is make sure they're actually valid.
require 'test_helper'
class FixturesTest < ActiveSupport::TestCase
fixtures(:all).each do |fixture|
define_method("test: #{fixture} is valid") do
fixture_instances = @loaded_fixtures[fixture]
invalid_fixtures = fixture_instances.keys.select do |fixture_name|
!fixture_instances[fixture_name].find.valid?
end
assert_equal 0, invalid_fixtures.length, "Expected #{fixture} fixtures to be valid, but #{invalid_fixtures.to_sentence} #{invalid_fixtures.length == 1 ? "is" : "are"} not."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment