You won't be able to stub a controller action from within a request spec. However you can stub the AJAX request, so that the controller action is never reached. Webmock is a good choice.
Rspec: stub out controller action
-
24-06-2023 - |
문제
I'm writing request specs for one controller and I'd like to stub out another controller's method which is called via AJAX. The controller action in the AJAX call is for geolocating addresses, and its unrelated to the rest of the request. The controller action always renders nothing.
I've tried:
before :each
AddressesController.any_instance.stub(:update).and_return nil
end
However, that gives me an error:
Failure/Error: Unable to find matching line from backtrace
ActionView::MissingTemplate:
Missing template addresses/update, application/update
No view template exists for the action, since it always renders nothing.
Is there a way I can stub out the other controller's action entirely, or do I need to stub out the internals of the method instead?
해결책
다른 팁
See this thread for more clarification. Like you mentioned, you should stub out the internals of the method instead.
제휴하지 않습니다 StackOverflow