【问题标题】:rspec `with` must have at least one argument. error after upgrade to 3.1.0rspec `with` 必须至少有一个参数。升级到 3.1.0 后出错
【发布时间】:2014-09-10 18:58:00
【问题描述】:

我正在升级我们的代码库以使用 rspec 3.1.0,并在此处关注文档: https://relishapp.com/rspec/docs/upgrade

一个现有的测试我在运行 transspec 后得到以下错误。

"with 必须至少有一个参数。使用no_args 匹配器设置不接收参数的期望。"

这是测试。

  it 'does something' do
    expect(my_method).to receive(:resource)
      .with { |path| path.include? 'test' }.and_return({})
  end

新的synatx 不再收到块了吗?

【问题讨论】:

  • 什么是my_method?上面定义的resource 方法是什么?请向我们展示您正在测试的代码。
  • 您从哪个版本的 RSpec 升级?

标签: ruby-on-rails ruby-on-rails-3 rspec rspec-rails rspec3


【解决方案1】:

这在 2.99 版中已弃用,并在 rspec 3 中删除。您可以在此处查看详细信息:https://github.com/rspec/rspec-mocks/issues/377

您可以使用以下方法完成相同的测试:

it 'does something' do
    expect(my_object).to receive(:resource).with(/test/).and_return({})
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 2015-07-18
    • 2019-04-27
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多