我将尝试这样模拟一个方法:
我正在尝试模拟一个方法,如下所示:
allow(Flipper).to receive(:enabled?).with(:premium_plus_features_beta).and_return(false)
但是当它遇到不同的参数时,会出现以下错误:
#<Flipper (class)> received :enabled? with unexpected arguments
expected: (:premium_plus_features_beta)
got: (:non_advertiser_profile_amp, {:lawyer_id=>4469860})
Diff:
@@ -1,2 +1,2 @@
-[:premium_plus_features_beta]
+[:non_advertiser_profile_amp, {:lawyer_id=>4469860}]
我通常不会这么频繁地使用存根,但是为什么当我明确告诉它参数时,它为什么会在不同的参数上出错呢?很显然它们不一样。这只是一些语法问题吗?
编辑1
我尝试过这个,但不起作用 https://makandracards.com/makandra/30543-rspec-only-stub-a-method-when-a-particular-argument-is-passed
Flipper.should_receive(:enabled?).and_call_original
Flipper.should_receive(:enabled?).with(:premium_plus_features_beta).and_return(false)