Regression: capybara-webkit causes apps to return error 500 on some AJAX requests #228

jgonera opened this Issue Dec 14, 2011 · 3 comments


None yet
3 participants

jgonera commented Dec 14, 2011

This is a really weird one and started when I upgraded to 0.7.x. When your application makes an AJAX request with those headers:

req.setRequestHeader("X-Requested-With", "XMLHttpRequest");

for some reason when you run Capybara tests with capybara-webkit the AJAX request always fails with error 500. If I remove those headers, everything works fine. I prepared a minimal test case in a fresh Rails 3.1.3 app:

The app has just one action which returns a page that contains a script that makes an AJAX request to the root path, i.e. it requests the HTML of the page itself and prints it in the console. You can open it in the browser with JS console to see how it works.

Now run rspec spec. The spec will fail. Now, try removing the headers in app/views/test/index.html.erb, it will succeed. Also, if you change to selenium it will work as expected. After running a test, see log/test.log, the error 500 will appear there but with no stack trace whatsoever.

til commented Dec 14, 2011

I ran into this too, here's a snippet of the rails stack trace I was able to see after some tweaks:

undefined method `ref' for nil:NilClass
activesupport (3.1.3) lib/active_support/whiny_nil.rb:48:in `method_missing'
actionpack (3.1.3) lib/action_controller/metal/rendering.rb:9:in `block in process_action

Setting the Accept header explicitely fixed the problem for me:

page.driver.header('accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')

No idea if this was introduced by rails (I'm using 3.1.3) recently, or has been there for long. I guess though that setting an accept header to a reasonable default would make sense for capybara-webkit.

jgonera commented Dec 14, 2011

I also started an issue about this for Rails (rails/rails#3985). I guess even if the Accept header is obligatory (and I'm not sure if it is), Rails shouldn't just blow up like this. The weird thing is that it works fine without the Accept header as long as there is also no X-Requested-With header.


halogenandtoast commented Jan 13, 2012

The spec you wrote currently passes for me. I'm going to assume this was an issue in some dependency and close this issue. If you find this is not the case can you reopen the issue and provide any details you can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment