Merge pull request #5960 from betagouv/fix-warnings
Suppression de nouveaux messages d'avertissements pendant les tests et lors de l'exécution de commandes `bin/rails` (#5960)
This commit is contained in:
commit
3969556e31
11 changed files with 123 additions and 115 deletions
2
Gemfile
2
Gemfile
|
@ -39,7 +39,7 @@ gem 'groupdate'
|
|||
gem 'haml-rails'
|
||||
gem 'hashie'
|
||||
gem 'http_accept_language'
|
||||
gem 'i18n-tasks'
|
||||
gem 'i18n-tasks', require: false
|
||||
gem 'iban-tools'
|
||||
gem 'image_processing'
|
||||
gem 'json_schemer'
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
# We want to register an interceptor, but we can't make the action idempotent
|
||||
# (because there's no way to peek at the currently registered interceptors).
|
||||
#
|
||||
# To make zeitwerk happy, instead signal that we don't want the
|
||||
# DynamicSmtpSettingsInterceptor constant to be auto-loaded, by:
|
||||
# - adding it to a non-autoloaded-path (/lib),
|
||||
# - requiring it explicitely.
|
||||
#
|
||||
# See https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots
|
||||
require 'action_mailer/dynamic_smtp_settings_interceptor'
|
||||
|
||||
ActiveSupport.on_load(:action_mailer) do
|
||||
ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor"
|
||||
ActionMailer::Base.register_interceptor DynamicSmtpSettingsInterceptor
|
||||
end
|
||||
|
|
|
@ -2,13 +2,18 @@
|
|||
# The generated `.rspec` file contains `--require rails_helper` which will cause
|
||||
# this file to always be loaded, without a need to explicitly require it in any
|
||||
# files.
|
||||
|
||||
require 'spec_helper'
|
||||
ENV['RAILS_ENV'] ||= 'test'
|
||||
require File.expand_path('../config/environment', __dir__)
|
||||
require 'spec_helper'
|
||||
# Prevent database truncation if the environment is production
|
||||
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
||||
require 'rspec/rails'
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
require 'axe/rspec'
|
||||
require 'devise'
|
||||
require 'shoulda-matchers'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||
# run as spec files by default. This means that files in spec/support that end
|
||||
|
@ -22,16 +27,25 @@ require 'rspec/rails'
|
|||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# require only the support files necessary.
|
||||
#
|
||||
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
||||
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
||||
Dir[Rails.root.join('spec/factories/**/*.rb')].each { |f| require f }
|
||||
|
||||
ActiveSupport::Deprecation.silenced = true
|
||||
|
||||
# Checks for pending migrations before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove this line.
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
begin
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
rescue ActiveRecord::PendingMigrationError => e
|
||||
puts e.to_s.strip
|
||||
exit 1
|
||||
end
|
||||
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
|
||||
TPS::Application.load_tasks
|
||||
Rake.application.options.trace = false
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Since rspec 3.8.0, bisect uses fork to improve bisection speed.
|
||||
# This however fails as soon as we're running feature tests (which uses many processes).
|
||||
|
@ -63,6 +77,22 @@ RSpec.configure do |config|
|
|||
|
||||
config.infer_base_class_for_anonymous_controllers = false
|
||||
|
||||
config.before(:all) do
|
||||
Rake.verbose false
|
||||
|
||||
Typhoeus::Expectation.clear
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
ActiveStorage::Current.host = 'http://test.host'
|
||||
|
||||
Geocoder.configure(lookup: :test)
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
Flipper.enable(:instructeur_bypass_email_login_token)
|
||||
end
|
||||
|
||||
config.include Shoulda::Matchers::ActiveRecord, type: :model
|
||||
config.include Shoulda::Matchers::ActiveModel, type: :model
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
|
|
|
@ -17,95 +17,6 @@
|
|||
#
|
||||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
||||
|
||||
require 'capybara/rspec'
|
||||
require 'capybara-screenshot/rspec'
|
||||
require 'capybara/email/rspec'
|
||||
require 'database_cleaner'
|
||||
require 'webmock/rspec'
|
||||
require 'shoulda-matchers'
|
||||
require 'devise'
|
||||
require 'factory_bot'
|
||||
require 'axe/rspec'
|
||||
|
||||
require 'selenium/webdriver'
|
||||
Capybara.javascript_driver = :headless_chrome
|
||||
Capybara.ignore_hidden_elements = false
|
||||
|
||||
Capybara.register_driver :chrome do |app|
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
||||
end
|
||||
|
||||
Capybara.register_driver :headless_chrome do |app|
|
||||
options = Selenium::WebDriver::Chrome::Options.new
|
||||
options.add_argument('--headless')
|
||||
options.add_argument('--window-size=1440,900')
|
||||
|
||||
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
||||
chromeOptions: { args: ['disable-dev-shm-usage', 'disable-software-rasterizer', 'mute-audio', 'window-size=1440,900'] }
|
||||
)
|
||||
|
||||
download_path = Capybara.save_path
|
||||
# Chromedriver 77 requires setting this for headless mode on linux
|
||||
# Different versions of Chrome/selenium-webdriver require setting differently - just set them all
|
||||
options.add_preference('download.default_directory', download_path)
|
||||
options.add_preference(:download, default_directory: download_path)
|
||||
|
||||
Capybara::Selenium::Driver.new(app,
|
||||
browser: :chrome,
|
||||
desired_capabilities: capabilities,
|
||||
options: options).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = download_path
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: remove this line when https://github.com/rspec/rspec-rails/issues/1897 has been fixed
|
||||
Capybara.server = :puma, { Silent: true }
|
||||
|
||||
Capybara.default_max_wait_time = 2
|
||||
|
||||
# Save a snapshot of the HTML page when an integration test fails
|
||||
Capybara::Screenshot.autosave_on_failure = true
|
||||
# Keep only the screenshots generated from the last failing test suite
|
||||
Capybara::Screenshot.prune_strategy = :keep_last_run
|
||||
# Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver
|
||||
Capybara::Screenshot.register_driver :headless_chrome do |driver, path|
|
||||
driver.browser.save_screenshot(path)
|
||||
end
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
||||
Dir[Rails.root.join('spec', 'factories', '**', '*.rb')].each { |f| require f }
|
||||
|
||||
VCR.configure do |c|
|
||||
c.ignore_localhost = true
|
||||
c.hook_into :webmock
|
||||
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
||||
c.configure_rspec_metadata!
|
||||
c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com'
|
||||
end
|
||||
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
|
||||
TPS::Application.load_tasks
|
||||
Rake.application.options.trace = false
|
||||
|
||||
include Warden::Test::Helpers
|
||||
|
||||
include SmartListing::Helper
|
||||
include SmartListing::Helper::ControllerExtensions
|
||||
|
||||
module SmartListing
|
||||
module Helper
|
||||
def view_context
|
||||
'mock'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.filter_run_excluding disable: true
|
||||
config.color = true
|
||||
|
@ -119,26 +30,6 @@ RSpec.configure do |config|
|
|||
# See https://github.com/rails/spring/issues/113
|
||||
config.seed = srand % 0xFFFF unless ARGV.any? { |arg| arg =~ /seed/ || arg =~ /rand:/ }
|
||||
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
|
||||
config.before(:each) do
|
||||
Flipper.enable(:instructeur_bypass_email_login_token)
|
||||
end
|
||||
|
||||
config.before(:all) {
|
||||
Rake.verbose false
|
||||
|
||||
Warden.test_mode!
|
||||
|
||||
Typhoeus::Expectation.clear
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
ActiveStorage::Current.host = 'http://test.host'
|
||||
|
||||
Geocoder.configure(lookup: :test)
|
||||
}
|
||||
|
||||
RSpec::Matchers.define :have_same_attributes_as do |expected, options|
|
||||
match do |actual|
|
||||
ignored = [:id, :procedure_id, :updated_at, :created_at]
|
||||
|
|
49
spec/support/capybara.rb
Normal file
49
spec/support/capybara.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'capybara/rspec'
|
||||
require 'capybara-screenshot/rspec'
|
||||
require 'capybara/email/rspec'
|
||||
require 'selenium/webdriver'
|
||||
|
||||
Capybara.javascript_driver = :headless_chrome
|
||||
Capybara.ignore_hidden_elements = false
|
||||
|
||||
Capybara.register_driver :chrome do |app|
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
||||
end
|
||||
|
||||
Capybara.register_driver :headless_chrome do |app|
|
||||
options = Selenium::WebDriver::Chrome::Options.new
|
||||
options.add_argument('--headless')
|
||||
options.add_argument('--window-size=1440,900')
|
||||
|
||||
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
||||
chromeOptions: { args: ['disable-dev-shm-usage', 'disable-software-rasterizer', 'mute-audio', 'window-size=1440,900'] }
|
||||
)
|
||||
|
||||
download_path = Capybara.save_path
|
||||
# Chromedriver 77 requires setting this for headless mode on linux
|
||||
# Different versions of Chrome/selenium-webdriver require setting differently - just set them all
|
||||
options.add_preference('download.default_directory', download_path)
|
||||
options.add_preference(:download, default_directory: download_path)
|
||||
|
||||
Capybara::Selenium::Driver.new(app,
|
||||
browser: :chrome,
|
||||
desired_capabilities: capabilities,
|
||||
options: options).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = download_path
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: remove this line when https://github.com/rspec/rspec-rails/issues/1897 has been fixed
|
||||
Capybara.server = :puma, { Silent: true }
|
||||
|
||||
Capybara.default_max_wait_time = 2
|
||||
|
||||
# Save a snapshot of the HTML page when an integration test fails
|
||||
Capybara::Screenshot.autosave_on_failure = true
|
||||
# Keep only the screenshots generated from the last failing test suite
|
||||
Capybara::Screenshot.prune_strategy = :keep_last_run
|
||||
# Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver
|
||||
Capybara::Screenshot.register_driver :headless_chrome do |driver, path|
|
||||
driver.browser.save_screenshot(path)
|
||||
end
|
10
spec/support/smart_listing.rb
Normal file
10
spec/support/smart_listing.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
include SmartListing::Helper
|
||||
include SmartListing::Helper::ControllerExtensions
|
||||
|
||||
module SmartListing
|
||||
module Helper
|
||||
def view_context
|
||||
'mock'
|
||||
end
|
||||
end
|
||||
end
|
7
spec/support/vcr.rb
Normal file
7
spec/support/vcr.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
VCR.configure do |c|
|
||||
c.ignore_localhost = true
|
||||
c.hook_into :webmock
|
||||
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
||||
c.configure_rspec_metadata!
|
||||
c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com'
|
||||
end
|
7
spec/support/warden.rb
Normal file
7
spec/support/warden.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
include Warden::Test::Helpers
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before(:all) do
|
||||
Warden.test_mode!
|
||||
end
|
||||
end
|
3
spec/support/webmock.rb
Normal file
3
spec/support/webmock.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require 'webmock/rspec'
|
||||
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
Loading…
Reference in a new issue