From c8e2328b15e5bb0070cec37c51dc2cca8e9113a2 Mon Sep 17 00:00:00 2001 From: Daniel Dye Date: Tue, 2 Jan 2024 16:47:43 +0000 Subject: [PATCH 1/4] Set OmniAuth logger to Rails logger This silences stdout messages while running rspec --- config/initializers/omniauth.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 1899588c7..6c97a8902 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,3 +1,5 @@ +OmniAuth.config.logger = Rails.logger + # Implementation inspired by register-trainee-teachers repo case ENV.fetch("SIGN_IN_METHOD") when "persona" From 968a6fda8adcdc305cd586c265f7eacb3cd863b7 Mon Sep 17 00:00:00 2001 From: Daniel Dye Date: Tue, 2 Jan 2024 17:03:43 +0000 Subject: [PATCH 2/4] Update Capybara configuration Capybara's default chrome headless driver is :selenium_chrome_headless. Override that one. Use --headless=new. See more: https://developer.chrome.com/docs/chromium/new-headless `js: true` is a default supported option for Capybara. We only need to set the system tests to be driven by Capybara's current driver. --- spec/support/capybara.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 489aff4cf..715a5ba5e 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -7,26 +7,22 @@ Capybara.always_include_port = true -Capybara.register_driver :chrome_headless do |app| - options = Selenium::WebDriver::Chrome::Options.new - - options.add_argument("--headless") unless ENV["HEADLESS"] == "false" - options.add_argument("--no-sandbox") - options.add_argument("--disable-dev-shm-usage") - options.add_argument("--disable-gpu") - options.add_argument("--window-size=1400,1400") +Capybara.register_driver :selenium_chrome_headless do |app| + options = Selenium::WebDriver::Chrome::Options.new.tap do |opts| + opts.add_argument("--headless=new") + opts.add_argument("--no-sandbox") + opts.add_argument("--disable-dev-shm-usage") + opts.add_argument("--disable-gpu") + opts.add_argument("--window-size=1400,1400") + end Capybara::Selenium::Driver.new(app, browser: :chrome, options:) end -Capybara.javascript_driver = :chrome_headless +Capybara.javascript_driver = :selenium_chrome_headless RSpec.configure do |config| config.before(:each, type: :system) do - if self.class.metadata[:js] == true - driven_by(:chrome_headless) - else - driven_by(:rack_test) - end + driven_by Capybara.current_driver end end From b2a311e76e2554b6623627d8c1b69f170238bc6c Mon Sep 17 00:00:00 2001 From: Daniel Dye Date: Tue, 2 Jan 2024 17:04:07 +0000 Subject: [PATCH 3/4] Use js: true to enable javascript in js-dependent system spec --- .../providers/support_user_adds_a_provider_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/system/placements/providers/support_user_adds_a_provider_spec.rb b/spec/system/placements/providers/support_user_adds_a_provider_spec.rb index bb2459d10..f7481aca3 100644 --- a/spec/system/placements/providers/support_user_adds_a_provider_spec.rb +++ b/spec/system/placements/providers/support_user_adds_a_provider_spec.rb @@ -1,9 +1,6 @@ require "rails_helper" -# Changing type from feature => system stops the javascript working. -# Will attempt to resolve in another PR. -RSpec.describe "Placements / Providers / Support User adds a Provider", - type: :feature do +RSpec.describe "Placements / Providers / Support User adds a Provider", type: :system, js: true do before do next_year = Time.current.next_year.year From 7ed6815736914f3150ce16e05115610d4b8b9d7c Mon Sep 17 00:00:00 2001 From: Daniel Dye Date: Tue, 2 Jan 2024 17:04:28 +0000 Subject: [PATCH 4/4] Use http in tests to avoid TLS errors --- spec/system/claims/view_organisations_spec.rb | 2 +- spec/system/placements/view_organisations_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/claims/view_organisations_spec.rb b/spec/system/claims/view_organisations_spec.rb index 62b7f87fe..8dbf7373f 100644 --- a/spec/system/claims/view_organisations_spec.rb +++ b/spec/system/claims/view_organisations_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "View organisations", type: :system do around do |example| - Capybara.app_host = "https://#{ENV["CLAIMS_HOST"]}" + Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}" example.run Capybara.app_host = nil end diff --git a/spec/system/placements/view_organisations_spec.rb b/spec/system/placements/view_organisations_spec.rb index bafaea882..f4b70e59d 100644 --- a/spec/system/placements/view_organisations_spec.rb +++ b/spec/system/placements/view_organisations_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "View organisations", type: :system do around do |example| - Capybara.app_host = "https://#{ENV["PLACEMENTS_HOST"]}" + Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}" example.run Capybara.app_host = nil end