Vcr with Capybara-Webkit

vcr with capybara-webkit

Unfortunately, VCR is very much incompatible with capybara-webkit. The fact is that capybara webkit is using webkit, which is in c. Webmock and Fakeweb, which are the basis for VCR, can only be used for Ruby web requests. Making the two work together would likely be a monumental task.

I've solved this problem two ways:

The first (hacky, but valid) is to add a new javascript file to the application that is only included in the test environment. This file stubs out the JS classes which make external web requests. Aside from the pure hackatude of this approach, it requires that every time a new request is added or changed you must change the stubs as well.

The second approach is to route all external requests through my own server, effectively proxying all external requests through my server. This has the huge disadvantage that you have to have an action for everything you want to consume (you could genericize it, with some work). It also suffers from the fact that it could as much as double the time for the request to complete. However, since the requests are now being made by Ruby you can use VCR in all it's glory.

In my situations, approach #2 has been much more to my advantage thanks to the fact that I need ruby to manipulate the data so that I can keep my javascript source-agnostic. I was, however, using approach #1 for quite a while successfully.

VCRProxy: Record PhantomJS ajax calls with VCR inside Capybara

So I did some research and now I have a very basic example of a working VCR proxy server, that handles HTTPS calls as a MITM proxyserver (if you deactivate the security check in your client). I would be very happy if someone could contribute and help me to bring this thing to life.

Here is the github repo: https://github.com/23tux/vcr_proxy

Rspec capybara spec fails when invoked via 'rake spec' but passes when invoked via 'rspec spec'

The problem was actually the gem rails_admin and how it was interacting with rake. It was fixed by adding the following to spec_helper.rb:

ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'false'

Capybara webkit invalid response error, how to debug?

The error you're seeing is most likely capybara-webkit's cryptic way of telling you that there is some sort of exception in the page. I had the same problem a while back, and the "Unable to load URL" thing totally threw me off, making it hard to find the actual problem.

As a few things to try, I'd suggest:

  • Make sure you have the latest version of capybara-webkit installed.
  • Check elements of the test other than the actual form, e.g. the controller logic and any models that are involved. Strip everything out until you have nothing.
  • Check out the discussion on this issue and follow leads from there. I'm pretty sure it's the same problem or a related one.

Good luck!



Related Topics



Leave a reply



Submit