Skip to content

Instantly share code, notes, and snippets.

@webmat
Created May 28, 2010 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmat/417146 to your computer and use it in GitHub Desktop.
Save webmat/417146 to your computer and use it in GitHub Desktop.
# In my test_helper
def self.should_have_valid_test_data
klass = self.name[/^(.*)Test$/, 1].constantize
test "#{klass.name} should have valid fixtures" do
invalids = klass.all.reject{|m|m.valid?}
message = "Expected all #{klass.name} fixtures to be valid.\nInvalids:\n#{
invalids.map{|m| [m.errors.full_messages, m]}.pretty_inspect}"
assert_block(message) { invalids.empty? }
end
test "#{klass.name} should have a valid factory" do
f = Factory.build(klass.name.downcase.to_sym)
f.valid?
message = "Expected #{name} factory to be valid.\nErrors:\n#{f.errors.full_messages.pretty_inspect}"
assert_block(message) { f.valid? }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment