سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

See this thread for more clarification. Like you mentioned, you should stub out the internals of the method instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top