How to stub a Rails helper / module method in the Rspec 3 spec spec?
I've seen this using the old syntax should_receive
, but I can't figure out how to stub a Rails module method in Rspec 3.
I've tried these:
OptionsHelper.stubs(:method).returns("something")
allow(OptionsHelper).to receive(:method).and_return "something"
allow_any_instance_of(ActionView::Base).to receive(:render_quick_help).and_return 'something'
But nobody actually stubs out the method.
+3
source to share
1 answer
allow_any_instance_of(ActionView::Base)
It is expected that an instance of this exact class, and not classes inheriting from it, will receive an instance of the method.
Also ActionView :: Base is a class, ActionView :: is a module.
Also, modules cannot be instantiated, so in theory allow_any_instance_of (ActionView) .to ... will have no effect.
I know this is not a solution, but should point you in the right direction.
+1
source to share