Skip to content

Commit

Permalink
Merge pull request #3405 from DMPRoadmap/fix_rspec_tests_for_bootstra…
Browse files Browse the repository at this point in the history
…p_upgrade

Fix for failing Rubocop tests.
  • Loading branch information
benjaminfaure committed Apr 11, 2024
2 parents 0f805f6 + 708dee4 commit 56759df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
# config.action_view.annotate_rendered_view_with_filenames = true

config.i18n.enforce_available_locales = false

# Add config/routes_test.rb to routes
config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb')
end

# Used by Rails' routes url_helpers (typically when including a link in an email)
Expand Down
9 changes: 9 additions & 0 deletions config/routes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

Rails.application.routes.draw do
# Define your test-specific routes here

# This route will return an empty response with a 200 OK status code
# when the browser requests the favicon.ico file.
get '/favicon.ico', to: proc { |_env| [200, {}, ['']] }
end
12 changes: 11 additions & 1 deletion spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
# Use the fast rack_test driver for non-feature tests by default
Capybara.default_driver = :rack_test

# Create a custom driver based on Capybara's :selenium_chrome_headless driver
# This resolves a ElementClickInterceptedError when executing `click_button 'Sign in'` with DMP Assistant
Capybara.register_driver :selenium_chrome_headless_add_window_size do |app|
# Get a copy of the default options for Capybara's :selenium_chrome_headless driver
options = Capybara.drivers[:selenium_chrome_headless].call.options[:options].dup
options.add_argument('--window-size=1920,1080') # default window-size is only (800x600)
# Create a new Selenium driver with the customised options
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

RSpec.configure do |config|
config.before(:each, type: :feature, js: false) do
Capybara.use_default_driver
end

# Use the Selenium headless Chrome driver for feature tests
config.before(:each, type: :feature, js: true) do
Capybara.current_driver = :selenium_chrome_headless
Capybara.current_driver = :selenium_chrome_headless_add_window_size
end
end

0 comments on commit 56759df

Please sign in to comment.