Having some trouble setting up capybara-webkit on my Rails 4.2.1 app. Tests are running fine, links are being clicked, and ajax calls are working, but there's one odd issue with capybara-screenshot gem. I wanted to capture html screenshots with all assets loaded for a true representation.
After taking screenshots, I noticed that I was getting both 'png' and 'html' files. When looking at the 'html' file (e.g. file:///Users/monk/dev/things/tmp/capybara/screenshot_2015-08-31-16-06-51.840.html), the CSS wasn't loading. It seemed like the asset paths were different from where the screenshot files were located...
To address this, I made changes to my test environment configuration in 'config/environments/test.rb' by adding:
config.action_controller.asset_host = "file://#{::Rails.root}/public"
config.assets.compile = true
config.assets.digest = true
The first line sets a prefix for all asset URLs on the page, the second compiles assets, and the third adds a digest hash to asset files. This helped load CSS and JS as expected in the html screenshots.
But then came a new problem - now ajax calls weren't working correctly in tests, throwing an error:
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/things/ajax_calculate_it"
Changing the asset_host caused all ajax calls to fail in tests. Here's an example of an ajax call on my test page:
<a class="calculable" data-remote="true" rel="nofollow" data-method="post" href="/things/ajax_calculate_it?a=5&b=48">Calculate it</a>
It seems to be using GET instead of POST. There must be a simple configuration adjustment I'm missing. Any ideas?