2015-11-29 20:57:45 -05:00
|
|
|
require_relative 'support/unit/load_environment'
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2012-03-23 21:00:36 -04:00
|
|
|
require 'rspec/rails'
|
Fix inclusion to correctly disallow outside values
The inclusion matcher, when qualified with `in_array`, was using
AllowValueMatcher to check that values outside the array were disallowed
by the model (and then inverting its result). However, it should have
been using DisallowValueMatcher all this time. This commit fixes that.
Without this fix, the following error is raised when using the inclusion
matcher against a model which does not have the proper inclusion
validation on it:
undefined method `attribute_setter' for nil:NilClass
This happens because the inclusion matcher is a complex matcher, i.e.,
it runs a series of submatchers internally and the result of those
submatchers contributes to whether or not the matcher matches. If one of
those submatchers fails, the inclusion matcher immediately fails and
spits out the failure message associated with that submatcher.
However, there is a fundamental difference between AllowValueMatcher and
DisallowValueMatcher as it relates to how they function:
* AllowValueMatcher sets an attribute to a value on a record and expects
the record not to fail validation.
* DisallowValueMatcher sets an attribute to a value on a record, but
expects the record *to* fail validation.
The issue in this case is that, because AllowValueMatcher was used
instead of DisallowValueMatcher, the inclusion matcher thought that the
AllowValueMatcher failed, when in fact it passed (this result was just
inverted). So it tried to generate a failure message for a matcher that
didn't fail in the first place. By using DisallowValueMatcher, we set
the proper expectations.
2018-09-12 01:05:06 -04:00
|
|
|
require 'rspec/matchers/fail_matchers'
|
2014-12-24 16:28:35 -05:00
|
|
|
require 'shoulda-matchers'
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2015-10-07 13:09:59 -04:00
|
|
|
require 'spec_helper'
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2019-03-17 16:55:00 -04:00
|
|
|
$VERBOSE = true
|
|
|
|
|
2020-09-05 08:14:10 -04:00
|
|
|
Dir[File.join(File.expand_path('support/unit/**/*.rb', __dir__))].sort.each do |file|
|
2014-10-26 20:51:42 -04:00
|
|
|
require file
|
|
|
|
end
|
|
|
|
|
2010-12-13 17:28:59 -05:00
|
|
|
RSpec.configure do |config|
|
Fix inclusion to correctly disallow outside values
The inclusion matcher, when qualified with `in_array`, was using
AllowValueMatcher to check that values outside the array were disallowed
by the model (and then inverting its result). However, it should have
been using DisallowValueMatcher all this time. This commit fixes that.
Without this fix, the following error is raised when using the inclusion
matcher against a model which does not have the proper inclusion
validation on it:
undefined method `attribute_setter' for nil:NilClass
This happens because the inclusion matcher is a complex matcher, i.e.,
it runs a series of submatchers internally and the result of those
submatchers contributes to whether or not the matcher matches. If one of
those submatchers fails, the inclusion matcher immediately fails and
spits out the failure message associated with that submatcher.
However, there is a fundamental difference between AllowValueMatcher and
DisallowValueMatcher as it relates to how they function:
* AllowValueMatcher sets an attribute to a value on a record and expects
the record not to fail validation.
* DisallowValueMatcher sets an attribute to a value on a record, but
expects the record *to* fail validation.
The issue in this case is that, because AllowValueMatcher was used
instead of DisallowValueMatcher, the inclusion matcher thought that the
AllowValueMatcher failed, when in fact it passed (this result was just
inverted). So it tried to generate a failure message for a matcher that
didn't fail in the first place. By using DisallowValueMatcher, we set
the proper expectations.
2018-09-12 01:05:06 -04:00
|
|
|
config.include RSpec::Matchers::FailMatchers
|
|
|
|
|
2017-01-09 07:31:46 -05:00
|
|
|
UnitTests::ActionPackVersions.configure_example_group(config)
|
2014-10-26 20:51:42 -04:00
|
|
|
UnitTests::ActiveModelHelpers.configure_example_group(config)
|
|
|
|
UnitTests::ActiveModelVersions.configure_example_group(config)
|
|
|
|
UnitTests::ClassBuilder.configure_example_group(config)
|
|
|
|
UnitTests::ControllerBuilder.configure_example_group(config)
|
|
|
|
UnitTests::I18nFaker.configure_example_group(config)
|
|
|
|
UnitTests::MailerBuilder.configure_example_group(config)
|
|
|
|
UnitTests::ModelBuilder.configure_example_group(config)
|
|
|
|
UnitTests::RailsVersions.configure_example_group(config)
|
2015-01-21 17:46:26 -05:00
|
|
|
UnitTests::ActiveRecordVersions.configure_example_group(config)
|
|
|
|
UnitTests::ActiveModelVersions.configure_example_group(config)
|
2015-02-08 16:38:55 -05:00
|
|
|
UnitTests::DatabaseHelpers.configure_example_group(config)
|
|
|
|
UnitTests::ColumnTypeHelpers.configure_example_group(config)
|
2015-12-27 00:55:06 -05:00
|
|
|
UnitTests::ValidationMatcherScenarioHelpers.configure_example_group(config)
|
2018-01-26 14:33:27 -05:00
|
|
|
UnitTests::MessageHelpers.configure_example_group(config)
|
2014-10-26 20:51:42 -04:00
|
|
|
|
|
|
|
config.include UnitTests::Matchers
|
2015-12-24 15:05:26 -05:00
|
|
|
|
|
|
|
config.infer_spec_type_from_file_location!
|
2020-09-04 10:38:31 -04:00
|
|
|
config.example_status_persistence_file_path = 'spec/examples.txt'
|
|
|
|
config.alias_it_behaves_like_to(:it_supports, 'it supports')
|
2015-12-24 15:05:26 -05:00
|
|
|
|
|
|
|
config.before(:all, type: :controller) do
|
|
|
|
self.class.controller(ApplicationController) { }
|
|
|
|
end
|
2019-01-30 00:58:03 -05:00
|
|
|
|
|
|
|
config.before(:suite) do
|
|
|
|
I18n.backend.send(:init_translations)
|
|
|
|
end
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
2014-06-27 18:39:39 -04:00
|
|
|
|
2014-12-24 16:46:10 -05:00
|
|
|
ActiveSupport::Deprecation.behavior = :stderr
|
2014-10-22 20:54:36 -04:00
|
|
|
|
|
|
|
Shoulda::Matchers.configure do |config|
|
|
|
|
config.integrate do |with|
|
|
|
|
with.test_framework :rspec
|
|
|
|
with.library :rails
|
|
|
|
end
|
|
|
|
end
|