demarches-normaliennes/spec/spec_helper.rb
Pierre de La Morinerie 473a86b861 gems: remove guard
- It doesn't seem used a lot these days
- It has some incompatibility with rspec 4

We need to explicitely add the 'listen' gem now though.
2021-02-25 10:45:42 +00:00

169 lines
5.7 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The `.rspec` file contains `--require rails_helper`, which requires spec_helper.rb,
# causing this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# 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
config.tty = true
config.run_all_when_everything_filtered = true
config.filter_run :focus => true
config.order = 'random'
# Fix the seed not changing between runs when using Spring
# 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]
if options.present? && options[:except]
ignored = ignored + options[:except]
end
actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored)
end
end
# Asserts that a given select element exists in the page,
# and that the option(s) with the given value(s) are selected.
#
# Usage: expect(page).to have_selected_value('Country', selected: 'Australia')
#
# For large lists, this is much faster than `have_select(location, selected: value)`,
# as it doesnt check that every other options are not selected.
RSpec::Matchers.define(:have_selected_value) do |select_locator, options|
match do |page|
values = options[:selected].is_a?(String) ? [options[:selected]] : options[:selected]
select_element = page.first(:select, select_locator)
select_element && values.all? do |value|
select_element.first(:option, value).selected?
end
end
end
end