在我的 Gemfile 中
gem 'rspec-rails', '~> 3.3'
我发现,errors_on 匹配器移动到了另一个 gem:https://github.com/rspec/rspec-collection_matchers
我确信一定有一种方法可以在 RSpec 3 中实现相同的目标。
如何将 RSpec 2 have().errors_on 匹配器转换为 RSpec 3?
expect {
click_button(I18n.t('helpers.submit.accounting.update'))
}.to have(4).errors_on(:share_ksk, :central_office, :limit_value, :fix_disagio)
我试过:
expect {
click_button(I18n.t('helpers.submit.accounting.update'))
}.to have_validation_error(I18n.t('accounting.two_digits_after_decimal_point')).on(
:share_ksk,
:central_office,
:limit_value,
:fix_disagio)
关于 https://github.com/rspec/rspec-rails/issues/1033
但我收到 RSpec 错误:
undefined method `on' for #<RSpec::Matchers::BuiltIn::Has:0x00000005913368>
最佳答案
解决方案 1:
如您所知,您可以使用 rspec-collection_matchers
gem。
解决方案 2:您可以猴子修补 errors_on
到 ::ActiveModel::Validations
上,如上所示 here
关于rspec - 将 RSpec 2 "to have().errors_on"匹配器转换为 RSpec 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33777521/