2015-08-10 11:05:06 +02:00
|
|
|
|
# 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`.
|
2020-03-25 15:04:48 +01:00
|
|
|
|
# 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
|
2015-08-10 11:05:06 +02:00
|
|
|
|
# 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'
|
2018-07-02 12:37:41 +02:00
|
|
|
|
require 'capybara-screenshot/rspec'
|
2018-11-06 11:22:17 +01:00
|
|
|
|
require 'capybara/email/rspec'
|
2015-08-10 11:05:06 +02:00
|
|
|
|
require 'database_cleaner'
|
|
|
|
|
require 'webmock/rspec'
|
|
|
|
|
require 'shoulda-matchers'
|
|
|
|
|
require 'devise'
|
2018-01-23 17:15:42 +01:00
|
|
|
|
require 'factory_bot'
|
2020-06-26 15:55:26 +02:00
|
|
|
|
require 'axe/rspec'
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
2018-01-04 10:46:33 +01:00
|
|
|
|
require 'selenium/webdriver'
|
|
|
|
|
Capybara.javascript_driver = :headless_chrome
|
2016-12-14 17:13:40 +01:00
|
|
|
|
Capybara.ignore_hidden_elements = false
|
2018-01-04 10:46:33 +01:00
|
|
|
|
|
|
|
|
|
Capybara.register_driver :chrome do |app|
|
|
|
|
|
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Capybara.register_driver :headless_chrome do |app|
|
2019-08-21 16:51:46 +02:00
|
|
|
|
options = Selenium::WebDriver::Chrome::Options.new
|
|
|
|
|
options.add_argument('--headless')
|
|
|
|
|
options.add_argument('--window-size=1440,900')
|
|
|
|
|
|
2018-01-04 10:46:33 +01:00
|
|
|
|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
2020-03-19 17:13:52 +01:00
|
|
|
|
chromeOptions: { args: ['disable-dev-shm-usage', 'disable-software-rasterizer', 'mute-audio', 'window-size=1440,900'] }
|
2018-01-04 10:46:33 +01:00
|
|
|
|
)
|
|
|
|
|
|
2020-07-20 17:20:12 +02:00
|
|
|
|
download_path = Capybara.save_path
|
|
|
|
|
# Chromedriver 77 requires setting this for headless mode on linux
|
2020-07-21 17:11:40 +02:00
|
|
|
|
# Different versions of Chrome/selenium-webdriver require setting differently - just set them all
|
2020-07-20 17:20:12 +02:00
|
|
|
|
options.add_preference('download.default_directory', download_path)
|
|
|
|
|
options.add_preference(:download, default_directory: download_path)
|
|
|
|
|
|
|
|
|
|
Capybara::Selenium::Driver.new(app,
|
2018-01-04 10:46:33 +01:00
|
|
|
|
browser: :chrome,
|
2019-08-21 16:51:46 +02:00
|
|
|
|
desired_capabilities: capabilities,
|
2020-07-20 17:20:12 +02:00
|
|
|
|
options: options).tap do |driver|
|
|
|
|
|
# Set download dir for Chrome < 77
|
|
|
|
|
driver.browser.download_path = download_path
|
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-08 18:43:40 +02:00
|
|
|
|
# FIXME: remove this line when https://github.com/rspec/rspec-rails/issues/1897 has been fixed
|
|
|
|
|
Capybara.server = :puma, { Silent: true }
|
|
|
|
|
|
2018-08-07 12:30:54 +02:00
|
|
|
|
Capybara.default_max_wait_time = 2
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
2018-07-02 12:37:41 +02:00
|
|
|
|
# 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
|
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
|
|
|
# in spec/support/ and its subdirectories.
|
2018-03-06 13:44:29 +01:00
|
|
|
|
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
|
|
|
|
Dir[Rails.root.join('spec', 'factories', '**', '*.rb')].each { |f| require f }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
|
VCR.configure do |c|
|
|
|
|
|
c.ignore_localhost = true
|
|
|
|
|
c.hook_into :webmock
|
|
|
|
|
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
|
|
|
|
c.configure_rspec_metadata!
|
2019-11-05 15:47:55 +01:00
|
|
|
|
c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com'
|
2016-05-13 16:08:51 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-04-04 11:43:49 +02:00
|
|
|
|
DatabaseCleaner.strategy = :transaction
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
2018-06-20 11:29:02 +02:00
|
|
|
|
TPS::Application.load_tasks
|
2018-11-14 10:44:17 +01:00
|
|
|
|
Rake.application.options.trace = false
|
2018-06-20 11:29:02 +02:00
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
|
include Warden::Test::Helpers
|
|
|
|
|
|
2016-01-11 14:10:41 +01:00
|
|
|
|
include SmartListing::Helper
|
|
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
|
|
|
|
|
|
module SmartListing
|
|
|
|
|
module Helper
|
|
|
|
|
def view_context
|
|
|
|
|
'mock'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-08-24 11:42:06 +02:00
|
|
|
|
WebMock.disable_net_connect!(allow_localhost: true)
|
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
|
RSpec.configure do |config|
|
|
|
|
|
config.filter_run_excluding disable: true
|
|
|
|
|
config.color = true
|
|
|
|
|
config.tty = true
|
|
|
|
|
|
2017-10-06 10:17:07 +02:00
|
|
|
|
config.run_all_when_everything_filtered = true
|
2017-10-05 14:47:15 +02:00
|
|
|
|
config.filter_run :focus => true
|
2016-02-22 19:42:47 +01:00
|
|
|
|
|
2015-08-20 17:30:17 +02:00
|
|
|
|
config.order = 'random'
|
2018-07-25 19:35:18 +02:00
|
|
|
|
# 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:/ }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
2018-01-23 17:15:42 +01:00
|
|
|
|
config.include FactoryBot::Syntax::Methods
|
2016-05-13 16:08:51 +02:00
|
|
|
|
|
|
|
|
|
config.before(:each) do
|
2019-07-04 12:36:17 +02:00
|
|
|
|
Flipper.enable(:instructeur_bypass_email_login_token)
|
2016-05-13 16:08:51 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
config.before(:all) {
|
2018-06-12 18:17:37 +02:00
|
|
|
|
Rake.verbose false
|
|
|
|
|
|
2016-05-13 16:08:51 +02:00
|
|
|
|
Warden.test_mode!
|
|
|
|
|
|
2018-04-26 14:36:27 +02:00
|
|
|
|
Typhoeus::Expectation.clear
|
|
|
|
|
|
2018-11-06 17:05:23 +01:00
|
|
|
|
ActionMailer::Base.deliveries.clear
|
2019-12-19 18:29:01 +01:00
|
|
|
|
|
|
|
|
|
ActiveStorage::Current.host = 'http://test.host'
|
2020-01-14 19:00:17 +01:00
|
|
|
|
|
|
|
|
|
Geocoder.configure(lookup: :test)
|
2016-05-13 16:08:51 +02:00
|
|
|
|
}
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
2019-03-06 14:42:27 +01:00
|
|
|
|
RSpec::Matchers.define :have_same_attributes_as do |expected, options|
|
2016-06-15 11:34:05 +02:00
|
|
|
|
match do |actual|
|
|
|
|
|
ignored = [:id, :procedure_id, :updated_at, :created_at]
|
2019-03-06 14:42:27 +01:00
|
|
|
|
if options.present? && options[:except]
|
|
|
|
|
ignored = ignored + options[:except]
|
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
|
actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-06-03 15:47:56 +02:00
|
|
|
|
|
|
|
|
|
# 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 doesn’t 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
|
2015-08-10 11:05:06 +02:00
|
|
|
|
end
|