3.3' 我发现,errors_on 匹配器移动到了另一个 gem:https://github.com/rspec/rspe-6ren">
gpt4 book ai didi

rspec - 将 RSpec 2 "to have().errors_on"匹配器转换为 RSpec 3

转载 作者:行者123 更新时间:2023-12-05 07:52:22 32 4
gpt4 key购买 nike

在我的 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com