Skip to content

Instantly share code, notes, and snippets.

@zacksiri
Last active December 19, 2015 05:59
Show Gist options
  • Save zacksiri/5908153 to your computer and use it in GitHub Desktop.
Save zacksiri/5908153 to your computer and use it in GitHub Desktop.
for fixing capybara javascript test
# add these to your test group
group :test do
gem 'capybara'
gem 'poltergeist'
end
#spec/support/shared_db_connection.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
require 'capybara/poltergeist'
RSpec.configure do |config|
# ...
Capybara.javascript_driver = :poltergeist
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment