Merge branch 'rs-capybara-screenshot' into 'master'
Add capybara-screenshot gem This is a handy little gem that automatically saves the page and a screenshot when a Capybara test fails to `tmp/capybara/` so you can easily see why it might have failed without adding your own `save_and_open_page` directive in the code. Also reduces the timeout for Capybara tests when not in a CI environment. See merge request !578
This commit is contained in:
commit
f3ffd7d0b1
7 changed files with 67 additions and 37 deletions
5
Gemfile
5
Gemfile
|
@ -223,14 +223,13 @@ end
|
|||
group :development, :test do
|
||||
gem 'coveralls', require: false
|
||||
gem 'rubocop', '0.28.0', require: false
|
||||
# gem 'rails-dev-tweaks'
|
||||
gem 'spinach-rails'
|
||||
gem "rspec-rails", '2.99'
|
||||
gem "capybara", '~> 2.2.1'
|
||||
gem 'capybara', '~> 2.2.1'
|
||||
gem 'capybara-screenshot', '~> 1.0.0'
|
||||
gem "pry-rails"
|
||||
gem "awesome_print"
|
||||
gem "database_cleaner"
|
||||
gem "launchy"
|
||||
gem 'factory_girl_rails'
|
||||
|
||||
# Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826)
|
||||
|
|
|
@ -85,6 +85,9 @@ GEM
|
|||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
xpath (~> 2.0)
|
||||
capybara-screenshot (1.0.9)
|
||||
capybara (>= 1.0, < 3)
|
||||
launchy
|
||||
carrierwave (0.9.0)
|
||||
activemodel (>= 3.2.0)
|
||||
activesupport (>= 3.2.0)
|
||||
|
@ -677,6 +680,7 @@ DEPENDENCIES
|
|||
byebug
|
||||
cal-heatmap-rails (~> 0.0.1)
|
||||
capybara (~> 2.2.1)
|
||||
capybara-screenshot (~> 1.0.0)
|
||||
carrierwave
|
||||
charlock_holmes
|
||||
coffee-rails
|
||||
|
@ -726,7 +730,6 @@ DEPENDENCIES
|
|||
jquery-turbolinks
|
||||
jquery-ui-rails
|
||||
kaminari (~> 0.15.1)
|
||||
launchy
|
||||
letter_opener
|
||||
minitest (~> 5.3.0)
|
||||
mousetrap-rails
|
||||
|
|
24
features/support/capybara.rb
Normal file
24
features/support/capybara.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'spinach/capybara'
|
||||
require 'capybara/poltergeist'
|
||||
|
||||
# Give CI some extra time
|
||||
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10
|
||||
|
||||
Capybara.javascript_driver = :poltergeist
|
||||
Capybara.register_driver :poltergeist do |app|
|
||||
Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout)
|
||||
end
|
||||
|
||||
Spinach.hooks.on_tag("javascript") do
|
||||
Capybara.current_driver = Capybara.javascript_driver
|
||||
end
|
||||
|
||||
Capybara.default_wait_time = timeout
|
||||
Capybara.ignore_hidden_elements = false
|
||||
|
||||
unless ENV['CI'] || ENV['CI_SERVER']
|
||||
require 'capybara-screenshot/spinach'
|
||||
|
||||
# Keep only the screenshots generated from the last failing test suite
|
||||
Capybara::Screenshot.prune_strategy = :keep_last_run
|
||||
end
|
11
features/support/db_cleaner.rb
Normal file
11
features/support/db_cleaner.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'database_cleaner'
|
||||
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
|
||||
Spinach.hooks.before_scenario do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
Spinach.hooks.after_scenario do
|
||||
DatabaseCleaner.clean
|
||||
end
|
|
@ -11,10 +11,11 @@ ENV['RAILS_ENV'] = 'test'
|
|||
require './config/environment'
|
||||
require 'rspec'
|
||||
require 'rspec/expectations'
|
||||
require 'database_cleaner'
|
||||
require 'spinach/capybara'
|
||||
require 'sidekiq/testing/inline'
|
||||
|
||||
require_relative 'capybara'
|
||||
require_relative 'db_cleaner'
|
||||
|
||||
%w(select2_helper test_env repo_helpers).each do |f|
|
||||
require Rails.root.join('spec', 'support', f)
|
||||
end
|
||||
|
@ -22,29 +23,6 @@ end
|
|||
Dir["#{Rails.root}/features/steps/shared/*.rb"].each { |file| require file }
|
||||
|
||||
WebMock.allow_net_connect!
|
||||
#
|
||||
# JS driver
|
||||
#
|
||||
require 'capybara/poltergeist'
|
||||
Capybara.javascript_driver = :poltergeist
|
||||
Capybara.register_driver :poltergeist do |app|
|
||||
Capybara::Poltergeist::Driver.new(app, js_errors: false, timeout: 90)
|
||||
end
|
||||
Spinach.hooks.on_tag("javascript") do
|
||||
::Capybara.current_driver = ::Capybara.javascript_driver
|
||||
end
|
||||
Capybara.default_wait_time = 60
|
||||
Capybara.ignore_hidden_elements = false
|
||||
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
|
||||
Spinach.hooks.before_scenario do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
Spinach.hooks.after_scenario do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
|
||||
Spinach.hooks.before_run do
|
||||
include RSpec::Mocks::ExampleMethods
|
||||
|
|
|
@ -10,15 +10,9 @@ end
|
|||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'capybara/rails'
|
||||
require 'capybara/rspec'
|
||||
require 'webmock/rspec'
|
||||
require 'email_spec'
|
||||
require 'sidekiq/testing/inline'
|
||||
require 'capybara/poltergeist'
|
||||
|
||||
Capybara.javascript_driver = :poltergeist
|
||||
Capybara.default_wait_time = 10
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
|
|
21
spec/support/capybara.rb
Normal file
21
spec/support/capybara.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'capybara/rails'
|
||||
require 'capybara/rspec'
|
||||
require 'capybara/poltergeist'
|
||||
|
||||
# Give CI some extra time
|
||||
timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10
|
||||
|
||||
Capybara.javascript_driver = :poltergeist
|
||||
Capybara.register_driver :poltergeist do |app|
|
||||
Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout)
|
||||
end
|
||||
|
||||
Capybara.default_wait_time = timeout
|
||||
Capybara.ignore_hidden_elements = true
|
||||
|
||||
unless ENV['CI'] || ENV['CI_SERVER']
|
||||
require 'capybara-screenshot/rspec'
|
||||
|
||||
# Keep only the screenshots generated from the last failing test suite
|
||||
Capybara::Screenshot.prune_strategy = :keep_last_run
|
||||
end
|
Loading…
Reference in a new issue