The question is a bit odd formulated but what I want is an alternative for stub!
in Rspec which doesn't produce a deprecation warning.
The scenario:
I use stub!
to stub certain helper methods in my helper spec.
For instance
stub!(:t_with_partner_lookup).and_return("test")
Rspec than suggests to use stub
without the exclamation mark.
So I write (as suggested):
stub(:t_with_partner_lookup).and_return("test")
However this produces an error:
Stub :t_with_partner_lookup received unexpected message :and_return with ("test")
In another question that I found, I had to use the helper.
prefix. I did, but it didn't remove the deprecation warning instead it produced an error.
helper.stub(:t_with_partner_lookup).and_return("test")
Produces:
undefined method `t_with_partner_lookup' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x00000103256d50>
I also tried this syntax but that produces the same error as noted above:
helper.stub(:t_with_partner_lookup){"test"}
What is the correct syntax for stubbing a helper method?
Gems I use:
Ruby version 2.1.0
Solved it, by using the allow syntax:
allow(self).to receive(:t_with_partner_lookup).and_return("test")
I can suggest you to try
helper = Object.new.extend SomeHelper
helper.stub(:t_with_partner_lookup).and_return('test')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With