Skip to content

Instantly share code, notes, and snippets.

@mackermedia
Last active August 4, 2016 19:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mackermedia/3861750 to your computer and use it in GitHub Desktop.
Save mackermedia/3861750 to your computer and use it in GitHub Desktop.
Capybara + JS Testing
# place in spec/support/
Capybara.register_driver :poltergeist do |app|
options = {
:js_errors => true,
:window_size => [1280, 1440],
:timeout => 30
}
Capybara::Poltergeist::Driver.new(app, options)
end
# place in spec/support/features
module DatabaseCleanerHelper
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
Capybara.reset_sessions! # Forget the (simulated) browser state
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
end
end
end
require 'spec_helper'
describe "JS Example" do
it "doesn't use javascript driver" do
end
it "uses javascript driver", :js => true do
end
end
group :test do
gem 'capybara'
gem 'poltergeist' # gem 'capybara-webkit'
gem 'database_cleaner'
end
require 'capybara/poltergeist'
Capybara.configure do |config|
config.javascript_driver = :poltergeist
config.default_wait_time = 40 # long wait time for to handle jenkins timeouts
end
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.include DatabaseCleanerHelper, :type => :feature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment