这个问题有点奇怪,但我想要的是stub!Rspec 的另一种选择,它不会产生弃用警告.
场景:
我用来stub!在我的帮助器规范中存根某些辅助方法.
例如
stub!(:t_with_partner_lookup).and_return("test")
Run Code Online (Sandbox Code Playgroud)
Rspec比建议使用stub没有感叹号.
所以我写(如建议):
stub(:t_with_partner_lookup).and_return("test")
Run Code Online (Sandbox Code Playgroud)
但是这会产生错误:
Stub :t_with_partner_lookup received unexpected message :and_return with ("test")
Run Code Online (Sandbox Code Playgroud)
在我发现的另一个问题中,我不得不使用helper.前缀.我做了,但它没有删除弃用警告,而是产生了错误.
helper.stub(:t_with_partner_lookup).and_return("test")
Run Code Online (Sandbox Code Playgroud)
生产:
undefined method `t_with_partner_lookup' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x00000103256d50>
Run Code Online (Sandbox Code Playgroud)
我也尝试了这种语法,但产生了与上面提到的相同的错误:
helper.stub(:t_with_partner_lookup){"test"}
Run Code Online (Sandbox Code Playgroud)
用于存根辅助方法的正确语法是什么?
我使用的宝石:
Ruby版本2.1.0