RSpec:与快速通道一起使用时从错误模块调用"expect with"函数



我想将RSpec与fastlane一起使用,并按照RSpec的建议进行了设置。我想在我的测试中检查是否使用正确的参数调用了函数。我使用此处的示例代码来准确检查这一点: https://relishapp.com/rspec/rspec-mocks/v/3-2/docs/setting-constraints/matching-arguments

require 'spec_helper'
require 'rspec'
RSpec.describe "Constraining a message expectation using with" do
let(:dbl) { double }
before { expect(dbl).to receive(:foo).with(1, anything, /bar/) }

it "passes when the args match" do
dbl.foo(1, nil, "barn")
end
it "fails when the args do not match" do
dbl.foo(1, nil, "other")
end
end

当我使用"rspec"执行此操作时,这很好。没有错误,我得到了预期的结果。

但是,如果我像这样在我的 spec_helper.rb 文件中加载快车道操作

$LOAD_PATH.unshift File.expand_path('..', __dir__)
module SpecHelper
end
require 'fastlane'
Fastlane.load_actions
Fastlane.plugin_manager.load_plugins

我突然收到以下错误:

Constraining a message expectation using with passes when the args match
Failure/Error: before { expect(dbl).to receive(:foo).with(1, anything, /bar/) }
ArgumentError:
wrong number of arguments (given 3, expected 0..1)
# /Users/philip.otto/.rvm/gems/ruby-2.6.0/gems/facets-3.1.0/lib/core/facets/kernel/with.rb:15:in `with'
# ./spec/iz_create_release_branch_spec.rb:8:in `block (2 levels) in <top (required)>'

所以问题似乎是错误的函数"with"是从facets/kernel/with.rb中的另一个模块中获取的,而不是从rspec_mocks文件中正确获取的。

如何确保调用正确的函数?为什么首先调用这个错误的函数?

提前感谢您的帮助!

事实证明,这不是快车道的问题,而是我们添加到项目中的依赖项。依赖关系称为facets,它包含一个全局覆盖调用 using的每个函数的文件。

我在他们的GitHub上报告了它,我现在正在等待他们的答复。 报告链接

最新更新