【发布时间】:2014-06-07 10:32:55
【问题描述】:
自从我更新了我的 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>
我读到我现在应该使用“expect”而不是应该使用 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
【问题讨论】:
标签: ruby-on-rails rspec rspec3