Skip to content

Commit

Permalink
Added ability to set the JS driver for capybara
Browse files Browse the repository at this point in the history
Default is poltergeist

Sample commands to try:

DRIVER=chrome rspec
DRIVER=firefox rspec
DRIVER=webkit rspec
DRIVER=poltergeist rspec
  • Loading branch information
justin808 committed Sep 22, 2015
1 parent 6215a64 commit 63cf052
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ gem "therubyracer"

gem "autoprefixer-rails"

gem "awesome_print"

# Use Capistrano for deployment
# gem "capistrano-rails", group: :development
group :production do
Expand Down Expand Up @@ -87,6 +89,8 @@ group :test do
gem "capybara-screenshot"
gem "poltergeist"
gem "phantomjs", require: "phantomjs/poltergeist"
gem "selenium-webdriver"
gem "capybara-webkit"
gem "database_cleaner"
gem "launchy"
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GEM
autoprefixer-rails (5.2.1.1)
execjs
json
awesome_print (1.6.1)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.5.1)
Expand Down Expand Up @@ -74,6 +75,11 @@ GEM
capybara-screenshot (1.0.11)
capybara (>= 1.0, < 3)
launchy
capybara-webkit (1.6.0)
capybara (>= 2.3.0, < 2.5.0)
json
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
cliver (0.3.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -106,6 +112,7 @@ GEM
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
fastercsv (1.5.5)
ffi (1.9.10)
foreman (0.78.0)
thor (~> 0.19.1)
globalid (0.3.5)
Expand Down Expand Up @@ -221,6 +228,7 @@ GEM
sexp_processor (~> 4.0)
ruby_parser (3.7.0)
sexp_processor (~> 4.1)
rubyzip (1.1.7)
sass (3.4.16)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
Expand All @@ -234,6 +242,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (2.47.1)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
sexp_processor (4.6.0)
simplecov (0.10.0)
docile (~> 1.1.0)
Expand Down Expand Up @@ -280,6 +293,7 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.2)
websocket-driver (0.6.2)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
Expand All @@ -291,12 +305,14 @@ PLATFORMS

DEPENDENCIES
autoprefixer-rails
awesome_print
bootstrap-sass (~> 3.3.1)
brakeman
bundler-audit
byebug
capybara
capybara-screenshot
capybara-webkit
coffee-rails
coveralls
database_cleaner
Expand All @@ -319,6 +335,7 @@ DEPENDENCIES
sass-rails
scss_lint
sdoc
selenium-webdriver
spring
spring-commands-rspec
sqlite3
Expand Down
8 changes: 4 additions & 4 deletions spec/features/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end
end

shared_examples "Form" do
shared_examples "Comments Form" do
include_context "Form Submitted"

scenario "submits form", js: true do
Expand All @@ -33,7 +33,7 @@
click_link "Horizontal Form"
end

it_behaves_like "Form"
it_behaves_like "Comments Form"

context "iframe text" do
let(:iframe_text) { "<iframe src=\"http://www.w3schools.com\"></iframe>" }
Expand All @@ -51,14 +51,14 @@
click_link "Inline Form"
end

it_behaves_like "Form"
it_behaves_like "Comments Form"
end

context "Stacked Form" do
background do
click_link "Stacked Form"
end

it_behaves_like "Form"
it_behaves_like "Comments Form"
end
end
27 changes: 26 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,32 @@
DatabaseCleaner.clean
end

Capybara.javascript_driver = :poltergeist
driver = ENV["DRIVER"].try(:to_sym)
if driver.nil? || driver == :poltergeist
require "capybara/poltergeist"
Capybara.default_driver = :poltergeist
Capybara.current_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
elsif driver == :webkit
Capybara.default_driver = :webkit
Capybara.current_driver = :webkit
Capybara.javascript_driver = :webkit
elsif driver == :selenium
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.javascript_driver = :selenium
else # to use chrome, for example, with selenium
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: driver)
end
Capybara.default_driver = :selenium
Capybara.current_driver = :selenium
Capybara.javascript_driver = :selenium
end

puts "Capybara using driver: #{Capybara.default_driver}"

Capybara::Screenshot.prune_strategy = { keep: 10 }

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
Expand Down

0 comments on commit 63cf052

Please sign in to comment.