From 55831a4d50dc66973c0cfa28f58b5ac1a7c42ab7 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 14:20:15 -0400 Subject: Move Spinach setup for db_cleaner and capybara to their own files Also adds capybara-screenshot, which will automatically save the page as html and an image whenever a feature fails. Handy for debugging. --- features/support/capybara.rb | 19 +++++++++++++++++++ features/support/db_cleaner.rb | 11 +++++++++++ features/support/env.rb | 30 ++++-------------------------- 3 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 features/support/capybara.rb create mode 100644 features/support/db_cleaner.rb (limited to 'features') diff --git a/features/support/capybara.rb b/features/support/capybara.rb new file mode 100644 index 00000000000..9a2df74d7be --- /dev/null +++ b/features/support/capybara.rb @@ -0,0 +1,19 @@ +require 'spinach/capybara' +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 + +require 'capybara-screenshot/spinach' + +# Keep only the screenshots generated from the last failing test suite +Capybara::Screenshot.prune_strategy = :keep_last_run diff --git a/features/support/db_cleaner.rb b/features/support/db_cleaner.rb new file mode 100644 index 00000000000..1ab308cfa55 --- /dev/null +++ b/features/support/db_cleaner.rb @@ -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 diff --git a/features/support/env.rb b/features/support/env.rb index be17065ccfd..f34302721ed 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -11,40 +11,18 @@ 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 -Dir["#{Rails.root}/features/steps/shared/*.rb"].each {|file| require file} +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 -- cgit v1.2.1 From 1e3fc84cd1d0aa004fb69d18ca392af8877cc07a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 14:22:21 -0400 Subject: Reduce timeout for non-CI features --- features/support/capybara.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'features') diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 9a2df74d7be..8c6f4233278 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -1,16 +1,19 @@ 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: false, timeout: 90) + Capybara::Poltergeist::Driver.new(app, js_errors: false, timeout: timeout) end Spinach.hooks.on_tag("javascript") do Capybara.current_driver = Capybara.javascript_driver end -Capybara.default_wait_time = 60 +Capybara.default_wait_time = timeout Capybara.ignore_hidden_elements = false require 'capybara-screenshot/spinach' -- cgit v1.2.1 From 3875930793bf4e0274aabc4db7e3a31259d7297b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 14:37:11 -0400 Subject: Enable js_errors for Capybara in Spinach and RSpec --- features/support/capybara.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'features') diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 8c6f4233278..aaec9a6ece7 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -6,7 +6,7 @@ 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: false, timeout: timeout) + Capybara::Poltergeist::Driver.new(app, js_errors: true, timeout: timeout) end Spinach.hooks.on_tag("javascript") do -- cgit v1.2.1 From 652c15b585bac393b5c403a03355040eef51789c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 25 Apr 2015 17:22:44 -0400 Subject: Don't use capybara-screenshot in CI environments --- features/support/capybara.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'features') diff --git a/features/support/capybara.rb b/features/support/capybara.rb index aaec9a6ece7..31dbf0feb2f 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -16,7 +16,9 @@ end Capybara.default_wait_time = timeout Capybara.ignore_hidden_elements = false -require 'capybara-screenshot/spinach' +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 + # Keep only the screenshots generated from the last failing test suite + Capybara::Screenshot.prune_strategy = :keep_last_run +end -- cgit v1.2.1