ruby - RSpec:与 fastlane 一起使用时从错误的模块调用“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 文件中加载 fastlane 操作
$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 文件。
如何确保调用正确的函数?为什么首先调用这个错误的函数?
在此先感谢您的帮助!
解决方案
推荐阅读
- angular - 如何添加 nonce (CSP) 以允许 Spring boot Java Application 提供的 Angular SPA 页面上的内联 js/样式?
- r - 没有 S3Object 的 R(爪子)中的文本提取
- python - 如何用另一行的值替换空值
- python - 以 pdf 格式将列表/元组打印到表格中
- java - 从 Spring Data MongoDB 中的数组中删除多个文档引用
- flutter - 在 Flutter 中切换时在 CupertinoTabBar 中处理相机预览
- html - Shadow DOM 防止样式泄漏,但不能防止脚本泄漏
- javascript - 显示从功能开始点经过的时间
- java - 使用百分比在 Elasticsearch SpringBoot 中搜索匹配文本
- node.js - Flutter - HttpException:在收到完整标头之前连接已关闭