From 2b4d8fbd63ebc40111e5717b8f800a9a566d72b2 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 22 Jul 2021 11:01:51 +0100 Subject: [PATCH] Reorganise cuprite setup code --- ...ils_system_tests.rb => cuprite_helpers.rb} | 35 ++++++++----------- spec/system/support/cuprite_setup.rb | 26 +++++++------- 2 files changed, 27 insertions(+), 34 deletions(-) rename spec/system/support/{better_rails_system_tests.rb => cuprite_helpers.rb} (51%) diff --git a/spec/system/support/better_rails_system_tests.rb b/spec/system/support/cuprite_helpers.rb similarity index 51% rename from spec/system/support/better_rails_system_tests.rb rename to spec/system/support/cuprite_helpers.rb index e717fd1a23..0ec2d66335 100644 --- a/spec/system/support/better_rails_system_tests.rb +++ b/spec/system/support/cuprite_helpers.rb @@ -1,4 +1,18 @@ -module BetterRailsSystemTests +# frozen_string_literal: true + +module CupriteHelpers + # Drop #pause anywhere in a test to stop the execution. + # Useful when you want to checkout the contents of a web page in the middle of a test + # running in a headful mode. + def pause + page.driver.pause + end + + # Drop #debug anywhere in a test to open a Chrome inspector and pause the execution + def debug(*args) + page.driver.debug(*args) + end + # Use our `Capybara.save_path` to store screenshots with other capybara artifacts # (Rails screenshots path is not configurable https://github.com/rails/rails/blob/49baf092439fc74fc3377b12e3334c3dd9d0752f/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb#L79) def absolute_image_path @@ -13,22 +27,3 @@ module BetterRailsSystemTests Capybara.using_session(Capybara.last_used_session) { super } end end - -RSpec.configure do |config| - config.include BetterRailsSystemTests, type: :system - - # Make urls in mailers contain the correct server host. - # It's required for testing links in emails (e.g., via capybara-email). - config.around(:each, type: :system) do |ex| - was_host = Rails.application.default_url_options[:host] - Rails.application.default_url_options[:host] = Capybara.server_host - ex.run - Rails.application.default_url_options[:host] = was_host - end - - # Make sure this hook runs before others - config.prepend_before(:each, type: :system) do - # Use JS driver always - driven_by Capybara.javascript_driver - end -end diff --git a/spec/system/support/cuprite_setup.rb b/spec/system/support/cuprite_setup.rb index 315d3ca32c..8bc258f0b2 100644 --- a/spec/system/support/cuprite_setup.rb +++ b/spec/system/support/cuprite_setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "capybara/cuprite" Capybara.register_driver(:cuprite) do |app| @@ -19,20 +21,16 @@ end # Configure Capybara to use :cuprite driver by default Capybara.default_driver = Capybara.javascript_driver = :cuprite -module CupriteHelpers - # Drop #pause anywhere in a test to stop the execution. - # Useful when you want to checkout the contents of a web page in the middle of a test - # running in a headful mode. - def pause - page.driver.pause - end - - # Drop #debug anywhere in a test to open a Chrome inspector and pause the execution - def debug(*args) - page.driver.debug(*args) - end -end - RSpec.configure do |config| config.include CupriteHelpers, type: :system + + config.prepend_before(:each, type: :system) { driven_by :cuprite } + + # Make sure url helpers in mailers use the Capybara server host. + config.around(:each, type: :system) do |example| + original_host = Rails.application.default_url_options[:host] + Rails.application.default_url_options[:host] = Capybara.server_host + example.run + Rails.application.default_url_options[:host] = original_host + end end