【问题标题】:Convert RSpec 2 "to have().errors_on" matcher to RSpec 3将 RSpec 2“to have().errors_on”匹配器转换为 RSpec 3
【发布时间】:2015-11-18 10:26:34
【问题描述】:

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

【问题讨论】:

  • 我不知道你可以在一个块上调用 RSpec 2 匹配器。

标签: rspec rspec-rails rspec3


【解决方案1】:

解决方案 1: 如您所知,您可以使用rspec-collection_matchers gem。

解决方案 2:您可以像 here 一样将 errors_on 猴子修补到 ::ActiveModel::Validations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 2014-08-26
    • 2022-08-14
    相关资源
    最近更新 更多