Created
May 28, 2010 13:32
-
-
Save webmat/417146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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