thoughtbot/capybara-webkit — Issue #228: Regression: capybara-webkit causes apps to return error 500 on some AJAX requests
Author: jgonera
Created: 2011-12-14 16:00:38+00:00
State: open

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:

```js
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
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: https://github.com/jgonera/capybara-webkit-bug

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.