I am running integration tests for my Rails app using Cucumber with Capybara. I also use Spork for faster test runs. Capybara supports selenium and the headless poltergeist. Headless browser is good for faster test runs, but sometimes I also need to view what the browser is showing. This leads me to changing the Capybara driver and restarting spork.
Is there a way to change the Capybara driver without restarting spork?
Things that I have tried
[1] Added a module containing the driver code in features/support and referred that in Spork's each_run. It does not work and throws up an error.
[2] Using each_run to change the driver does not register the change until spork is restarted.
Spork.each_run do
Capybara.javascript_driver = :poltergeist
end
Figured it out. Capybara's github page had some information on this. Here's what I did:
Added the following code to features/support/hooks.rb
Before('@javascript') do
Capybara.current_driver = :poltergeist
end
This can be changed at any point without needing a Spork restart. I was unable to figure out a way to place it in the each_run block.