2011-07-18 28 views
3

這裏是我的RSpec的1.x代碼一些樣本測試:升級到RSpec 2:錯誤被替換爲have(n).errors_on?需要一個解決

[: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的,迫使我做這件事:

[: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 

我不在乎有多少錯誤,只是在驗證模型時出現錯誤。這將是很酷,如果我可以做這樣的事情:

e.should have.errors_on(attr) 

任何人有任何想法?

回答

4

你可以試試這個:

e.should have_at_least(1).error_on(attr) 
相關問題