I'm having trouble using Poltergeist as the driver for Capybara in Konacha tests run with Guard.
I have the following in config/initializers/konacha.rb:
Konacha.configure do |config|
require 'capybara/poltergeist'
config.spec_dir = "spec/javascripts"
config.spec_matcher = /_spec\.|_test\./
config.driver = :poltergeist
config.stylesheets = %w(manifest_public)
end if defined?(Konacha)
My tests run successfully in Poltergeist with bundle exec rake konacha:run
However, when I use the following Guardfile:
guard :konacha, driver: :poltergeist do
watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$})
end
Guard complains while starting Konacha:
14:18:05 - INFO - Starting Konacha
14:18:05 - ERROR -Capybara::DriverNotFoundError: no driver called :poltergeist was found, available drivers: :rack_test, :selenium>
I found a solution which works, but it seems a little hacky, so if anyone wants to suggest something better I'm all ears. I realized that the Konacha initializer is not being loaded until after Guard loads Konacha, so I had to replicate the registration of the Capybara::Poltergeist
driver in the Guardfile:
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {:js_errors => true})
end
guard :konacha, driver: :poltergeist do
watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$})
end