Upgrading to RSpec 2: errors replaced with have(n).errors_on? Need a work-around
Here is some sample tests from my rspec 1.x code:
[:email, :contact_type_id].each do |attr|
it "requires #{attr}" do
e = EmailAddress.new
e.should_not be_valid
# i don't care how many errors there are,
# just that there were errors for this attr.
e.errors(attr).should_not be_nil
end开发者_开发知识库
end
RSpec 2.6.x is forcing me to do this:
[:email, :contact_type_id].each do |attr|
it "requires #{attr}" do
e = EmailAddress.new
e.should_not be_valid
# have expects that I pass a number here :(
e.should have(n).error_on(attr)
end
end
I don't care HOW many errors there are, just that errors showed up when trying to validate the model. It would be cool if I could do something like:
e.should have.errors_on(attr)
Anyone got any ideas?
You can try this:
e.should have_at_least(1).error_on(attr)
精彩评论