Stubbing Ajax requests in Cucumber / Capybara / Selenium? Stubbing Ajax requests in Cucumber / Capybara / Selenium? selenium selenium

Stubbing Ajax requests in Cucumber / Capybara / Selenium?


The only way to do it is to change url or disable request depending on the environment application is run.

You can't stub this request from test side because this request is made by browser not by your application.

Also as temporary solution or solution for CI server you can disable this url in hosts file.


You can use puffing-billy https://github.com/oesmith/puffing-billy for that purpose. I'm using it to mock JSONP calls to Recurly in my app.


Capybara isn't aware of any requests stubbed via webmock as the requests are coming from capybara-webkit or firefox.

This thoughtbot article will guide you through it:
http://robots.thoughtbot.com/using-capybara-to-test-javascript-that-makes-http