demarches-normaliennes/spec/spec_helper.rb

62 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

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`.
# 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
RSpec.configure do |config|
config.filter_run_excluding disable: true
config.color = true
config.tty = true
config.example_status_persistence_file_path = 'failing_specs.txt'
config.run_all_when_everything_filtered = true
config.filter_run :focus => true
2015-08-20 17:30:17 +02:00
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:/ }
2015-08-10 11:05:06 +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
# 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
2015-08-10 11:05:06 +02:00
end