title: Stubbing Ajax requests in Cucumber / Capybara / Selenium?
body: <p>In my Rails 3.2 project, I send an occasional http request to <code>http://jsonip.com</code> from Javascript. But when running Cucumber with the <code>@javascript</code> tag, the request gets sent very frequently. This is obviously very undesirable and I would like to stub such requests. Now, I thought I could use the <code>stub_request</code> from <code>webmock</code> for this, like so:</p>
  
  <pre><code>Before do
    stub_request(:any, /.*jsonip.*/).to_return(:body =&gt; '{"ip":"24.104.73.2","about":"/about"}')
  end
  </code></pre>
  
  <p>but even with this in place, <code>jsonip</code> gets called from Javascript. And so I found that <code>webmock</code> does not actually stub Ajax request (at least not with the above <code>stub_request</code> statement). </p>
  
  <p>What is the right way to stub Ajax request in a Cucumber / Capybara / Selenium setup?</p>