由于我更新了我的 Gemfile 并移至 rspec 3,在许多测试中,我收到一个错误:方式:
it "should reject attribute that are too short" do
short = "a" * 3
hash = @attr.merge(:details => short)
Deal.new(hash).should have(1).error_on(:details)
end
我收到此错误:
Failure/Error: Deal.new(hash).should have(1).error_on(:details)
NoMethodError:
undefined method `have' for #<RSpec::ExampleGroups::Deal_2::TestsOnDealsModelsValidations>
我读到我现在应该使用“期望”而不是应该但是在这里have(1).error_on
,我应该如何编写它以符合 rspec 3?
我尝试了以下方法,但仍然无法正常工作:
it "should reject attribute that are too short" do
short = "a" * 3
hash = @attr.merge(:details => short)
expect(Deal.new(hash).error_on(:details).size).to eq(1)
end