mock/stub helper method on Controller Example of rspec
It’s kinda tricky if you want to mock helper methods on Controller Example with integrate_views of rspec::rails because template object won’t be created until you call a request method. But you presumably want to configure mock before calling a request on such situation. If you are using rr as your mock library, you can mock/stub the helper method like this:
it "should stub/mock helper_method"
stub.proxy(response).template do |tmpl|
stub(tmpl).your_helper_method { "stubbed" }
end
get :action_you_want_to_test
response.body.should =~ /stubbed/
end
There might be better ways, though, I think it is good enough.
Advertisement
