Ruby on rails 升级到rspec 3在使用时导致错误应具有(1)。错误\u on
由于我更新了我的GEM文件并移动到rspec 3,在许多测试中,我得到一个错误:way:Ruby on rails 升级到rspec 3在使用时导致错误应具有(1)。错误\u on,ruby-on-rails,rspec,rspec3,Ruby On Rails,Rspec,Rspec3,由于我更新了我的GEM文件并移动到rspec 3,在许多测试中,我得到一个错误:way: 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/Err
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>
已经
和其他类似的匹配器已经从rspec核心转移到另一个gem中
我建议按照rspec文档中详述的rspec 2->3的升级路径进行升级:
- 升级至rspec 2.99
- 运行您的测试套件
- 修复弃用警告
- 升级到rspec3
如果您这样做了,您的代码将收到一个弃用错误,该错误还将告诉您如何修复它。我已替换了
Deal.new(hash).should have(1).error_on(:details)
与
valid?
的第一个期望值是必要的,因为它初始化了错误列表。要添加到GEM文件的行应该是:
gem 'rspec-collection_matchers'
只需添加gem文件:gem“rspec集合匹配器”。
deal = Deal.new(hash)
expect(deal.valid?).to be_falsey
expect(deal.errors[:details].size).to eq(1)
gem 'rspec-collection_matchers'