shoulda-matchers 2.7.0 → 2.8.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/Appraisals +18 -0
- data/CONTRIBUTING.md +13 -29
- data/Gemfile +1 -4
- data/Gemfile.lock +2 -10
- data/NEWS.md +100 -14
- data/README.md +62 -58
- data/Rakefile +9 -16
- data/gemfiles/3.0.gemfile +11 -12
- data/gemfiles/3.0.gemfile.lock +15 -10
- data/gemfiles/3.1.gemfile +11 -12
- data/gemfiles/3.1.gemfile.lock +14 -10
- data/gemfiles/3.1_1.9.2.gemfile +12 -11
- data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
- data/gemfiles/3.2.gemfile +11 -12
- data/gemfiles/3.2.gemfile.lock +15 -10
- data/gemfiles/3.2_1.9.2.gemfile +12 -11
- data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
- data/gemfiles/4.0.0.gemfile +10 -12
- data/gemfiles/4.0.0.gemfile.lock +13 -10
- data/gemfiles/4.0.1.gemfile +10 -12
- data/gemfiles/4.0.1.gemfile.lock +13 -10
- data/gemfiles/4.1.gemfile +13 -15
- data/gemfiles/4.1.gemfile.lock +45 -50
- data/gemfiles/4.2.gemfile +36 -0
- data/gemfiles/4.2.gemfile.lock +245 -0
- data/lib/shoulda/matchers.rb +3 -1
- data/lib/shoulda/matchers/action_controller.rb +1 -1
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
- data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
- data/lib/shoulda/matchers/active_model.rb +1 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
- data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
- data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
- data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
- data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
- data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
- data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
- data/lib/shoulda/matchers/matcher_context.rb +35 -0
- data/lib/shoulda/matchers/rails_shim.rb +23 -0
- data/lib/shoulda/matchers/util.rb +28 -0
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/spec/acceptance/active_model_integration_spec.rb +20 -0
- data/spec/acceptance/independent_matchers_spec.rb +64 -0
- data/spec/acceptance/rails_integration_spec.rb +142 -0
- data/spec/acceptance_spec_helper.rb +23 -0
- data/spec/support/acceptance/helpers.rb +29 -0
- data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
- data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
- data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
- data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
- data/spec/support/acceptance/matchers/have_output.rb +31 -0
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
- data/spec/support/tests/bundle.rb +94 -0
- data/spec/support/tests/command_runner.rb +214 -0
- data/spec/support/tests/filesystem.rb +77 -0
- data/spec/support/tests/version.rb +45 -0
- data/spec/support/unit/capture.rb +34 -0
- data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
- data/spec/support/unit/helpers/active_model_versions.rb +20 -0
- data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
- data/spec/support/unit/helpers/class_builder.rb +72 -0
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
- data/spec/support/unit/helpers/controller_builder.rb +91 -0
- data/spec/support/unit/helpers/i18n_faker.rb +15 -0
- data/spec/support/unit/helpers/mailer_builder.rb +12 -0
- data/spec/support/unit/helpers/model_builder.rb +102 -0
- data/spec/support/unit/helpers/rails_versions.rb +28 -0
- data/spec/support/unit/i18n.rb +7 -0
- data/spec/support/unit/matchers/deprecate.rb +60 -0
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
- data/spec/support/unit/matchers/print_warning_including.rb +59 -0
- data/spec/support/unit/rails_application.rb +110 -0
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
- data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
- data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
- data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
- data/spec/{shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb → unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb} +43 -23
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
- data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
- data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
- data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
- data/spec/unit_spec_helper.rb +66 -0
- data/spec/warnings_spy/partitioner.rb +10 -3
- data/spec/warnings_spy/reader.rb +9 -20
- data/spec/warnings_spy/reporter.rb +2 -1
- metadata +212 -149
- data/features/activemodel_integration.feature +0 -15
- data/features/rails_integration.feature +0 -160
- data/features/step_definitions/activemodel_steps.rb +0 -21
- data/features/step_definitions/rails_steps.rb +0 -227
- data/features/support/env.rb +0 -6
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
- data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
- data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
- data/spec/spec_helper.rb +0 -42
- data/spec/support/active_model_versions.rb +0 -13
- data/spec/support/active_resource_builder.rb +0 -29
- data/spec/support/activemodel_helpers.rb +0 -23
- data/spec/support/capture_helpers.rb +0 -19
- data/spec/support/class_builder.rb +0 -46
- data/spec/support/controller_builder.rb +0 -102
- data/spec/support/fail_with_message_including_matcher.rb +0 -44
- data/spec/support/fail_with_message_matcher.rb +0 -44
- data/spec/support/i18n_faker.rb +0 -10
- data/spec/support/mailer_builder.rb +0 -10
- data/spec/support/model_builder.rb +0 -81
- data/spec/support/rails_versions.rb +0 -26
- data/spec/support/test_application.rb +0 -120
data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActionController do
|
3
|
+
describe Shoulda::Matchers::ActionController, type: :controller do
|
4
4
|
describe '#permit' do
|
5
5
|
it 'matches when the sent parameter is allowed' do
|
6
6
|
controller_for_resource_with_strong_parameters(action: :create) do
|
@@ -37,7 +37,7 @@ describe Shoulda::Matchers::ActionController do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe Shoulda::Matchers::ActionController::StrongParametersMatcher do
|
40
|
+
describe Shoulda::Matchers::ActionController::StrongParametersMatcher, type: :controller do
|
41
41
|
describe '#description' do
|
42
42
|
it 'returns the correct string' do
|
43
43
|
options = { action: :create, method: :post }
|
@@ -261,11 +261,12 @@ describe Shoulda::Matchers::ActionController::StrongParametersMatcher do
|
|
261
261
|
context 'when given :create' do
|
262
262
|
it 'POSTs to the controller' do
|
263
263
|
controller = ActionController::Base.new
|
264
|
-
context =
|
265
|
-
context.expects(:post).with(:create, {})
|
264
|
+
context = build_context
|
266
265
|
matcher = described_class.new([:name]).in_context(context).for(:create)
|
267
266
|
|
268
267
|
matcher.matches?(controller)
|
268
|
+
|
269
|
+
expect(context).to have_received(:post).with(:create, {})
|
269
270
|
end
|
270
271
|
end
|
271
272
|
|
@@ -273,20 +274,22 @@ describe Shoulda::Matchers::ActionController::StrongParametersMatcher do
|
|
273
274
|
if rails_gte_4_1?
|
274
275
|
it 'PATCHes to the controller' do
|
275
276
|
controller = ActionController::Base.new
|
276
|
-
context =
|
277
|
-
context.expects(:patch).with(:update, {})
|
277
|
+
context = build_context
|
278
278
|
matcher = described_class.new([:name]).in_context(context).for(:update)
|
279
279
|
|
280
280
|
matcher.matches?(controller)
|
281
|
+
|
282
|
+
expect(context).to have_received(:patch).with(:update, {})
|
281
283
|
end
|
282
284
|
else
|
283
285
|
it 'PUTs to the controller' do
|
284
286
|
controller = ActionController::Base.new
|
285
|
-
context =
|
286
|
-
context.expects(:put).with(:update, {})
|
287
|
+
context = build_context
|
287
288
|
matcher = described_class.new([:name]).in_context(context).for(:update)
|
288
289
|
|
289
290
|
matcher.matches?(controller)
|
291
|
+
|
292
|
+
expect(context).to have_received(:put).with(:update, {})
|
290
293
|
end
|
291
294
|
end
|
292
295
|
end
|
@@ -294,13 +297,14 @@ describe Shoulda::Matchers::ActionController::StrongParametersMatcher do
|
|
294
297
|
context 'when given a custom action and verb' do
|
295
298
|
it 'calls the action with the verb' do
|
296
299
|
controller = ActionController::Base.new
|
297
|
-
context =
|
298
|
-
context.expects(:delete).with(:hide, {})
|
300
|
+
context = build_context
|
299
301
|
matcher = described_class.new([:name]).
|
300
302
|
in_context(context).
|
301
303
|
for(:hide, verb: :delete)
|
302
304
|
|
303
305
|
matcher.matches?(controller)
|
306
|
+
|
307
|
+
expect(context).to have_received(:delete).with(:hide, {})
|
304
308
|
end
|
305
309
|
end
|
306
310
|
end
|
@@ -319,5 +323,9 @@ describe Shoulda::Matchers::ActionController::StrongParametersMatcher do
|
|
319
323
|
end
|
320
324
|
end
|
321
325
|
|
326
|
+
def build_context
|
327
|
+
double('context', post: nil, put: nil, patch: nil, delete: nil)
|
328
|
+
end
|
329
|
+
|
322
330
|
class SimulatedError < StandardError; end
|
323
331
|
end
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher, type: :model do
|
4
4
|
context '#description' do
|
5
5
|
context 'without a role' do
|
6
6
|
it 'includes the attribute name' do
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::AllowValueMatcher, type: :model do
|
4
4
|
context "#description" do
|
5
5
|
it 'describes itself with multiple values' do
|
6
6
|
matcher = allow_value('foo', 'bar').for(:baz)
|
@@ -88,27 +88,53 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
context '
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
context 'when the attribute being validated is different than the attribute that receives the validation error' do
|
92
|
+
include UnitTests::AllowValueMatcherHelpers
|
93
|
+
|
94
|
+
context 'when the validation error message was provided directly' do
|
95
|
+
it 'passes given a valid value' do
|
96
|
+
builder = builder_for_record_with_different_error_attribute
|
97
|
+
expect(builder.record).
|
98
|
+
to allow_value(builder.valid_value).
|
99
|
+
for(builder.attribute_to_validate).
|
100
|
+
with_message(builder.message,
|
101
|
+
against: builder.attribute_that_receives_error
|
102
|
+
)
|
103
|
+
end
|
96
104
|
|
97
|
-
|
98
|
-
|
99
|
-
|
105
|
+
it 'fails given an invalid value' do
|
106
|
+
builder = builder_for_record_with_different_error_attribute
|
107
|
+
invalid_value = "#{builder.valid_value} (invalid)"
|
108
|
+
expect(builder.record).
|
109
|
+
not_to allow_value(invalid_value).
|
110
|
+
for(builder.attribute_to_validate).
|
111
|
+
with_message(builder.message,
|
112
|
+
against: builder.attribute_that_receives_error
|
113
|
+
)
|
114
|
+
end
|
100
115
|
end
|
101
116
|
|
102
|
-
|
103
|
-
|
104
|
-
|
117
|
+
context 'when the validation error message was provided via i18n' do
|
118
|
+
it 'passes given a valid value' do
|
119
|
+
builder = builder_for_record_with_different_error_attribute_using_i18n
|
120
|
+
expect(builder.record).
|
121
|
+
to allow_value(builder.valid_value).
|
122
|
+
for(builder.attribute_to_validate).
|
123
|
+
with_message(builder.validation_message_key,
|
124
|
+
against: builder.attribute_that_receives_error
|
125
|
+
)
|
126
|
+
end
|
105
127
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
128
|
+
it 'fails given an invalid value' do
|
129
|
+
builder = builder_for_record_with_different_error_attribute_using_i18n
|
130
|
+
invalid_value = "#{builder.valid_value} (invalid)"
|
131
|
+
expect(builder.record).
|
132
|
+
not_to allow_value(invalid_value).
|
133
|
+
for(builder.attribute_to_validate).
|
134
|
+
with_message(builder.validation_message_key,
|
135
|
+
against: builder.attribute_that_receives_error
|
136
|
+
)
|
137
|
+
end
|
112
138
|
end
|
113
139
|
end
|
114
140
|
|
@@ -194,8 +220,10 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
|
|
194
220
|
|
195
221
|
matcher.matches?(validating_format(with: /abc/, strict: true))
|
196
222
|
|
197
|
-
expect(matcher.failure_message_when_negated).to eq
|
198
|
-
|
223
|
+
expect(matcher.failure_message_when_negated).to eq(
|
224
|
+
%{Expected exception to include /abc/ when attr is set to "xyz",\n} +
|
225
|
+
%{got: "Attr is invalid"}
|
226
|
+
)
|
199
227
|
end
|
200
228
|
end
|
201
229
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher, type: :model do
|
4
4
|
context 'an attribute with a format validation' do
|
5
5
|
it 'does not match if the value is allowed' do
|
6
6
|
expect(validating_format(with: /abc/)).not_to matcher('abcde').for(:attr)
|
@@ -36,8 +36,12 @@ describe Shoulda::Matchers::ActiveModel::DisallowValueMatcher do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "delegates its failure message to its allow matcher's negative failure message" do
|
39
|
-
allow_matcher =
|
40
|
-
|
39
|
+
allow_matcher = double('allow_matcher',
|
40
|
+
failure_message_when_negated: 'allow matcher failure',
|
41
|
+
).as_null_object
|
42
|
+
allow(Shoulda::Matchers::ActiveModel::AllowValueMatcher).
|
43
|
+
to receive(:new).
|
44
|
+
and_return(allow_matcher)
|
41
45
|
|
42
46
|
matcher = matcher('abcde').for(:attr).with_message('good message')
|
43
47
|
matcher.matches?(validating_format(with: /abc/, message: 'good message'))
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder, type: :model do
|
4
4
|
if active_model_3_2?
|
5
5
|
context '#allow_description' do
|
6
6
|
it 'describes its attribute' do
|
@@ -64,7 +64,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
64
64
|
|
65
65
|
description = finder.messages_description
|
66
66
|
|
67
|
-
expect(description).to eq 'Attr is invalid'
|
67
|
+
expect(description).to eq ': "Attr is invalid"'
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'describes errors when there are none' do
|
@@ -72,7 +72,7 @@ describe Shoulda::Matchers::ActiveModel::ExceptionMessageFinder do
|
|
72
72
|
|
73
73
|
description = finder.messages_description
|
74
74
|
|
75
|
-
expect(description).to eq 'no exception'
|
75
|
+
expect(description).to eq ' no exception'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher, type: :model do
|
4
4
|
if active_model_3_1?
|
5
5
|
it 'matches when the subject configures has_secure_password with default options' do
|
6
6
|
working_model = define_model(:example, password_digest: :string) { has_secure_password }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'unit_spec_helper'
|
3
3
|
|
4
4
|
describe Shoulda::Matchers::ActiveModel::Helpers do
|
5
5
|
include Shoulda::Matchers::ActiveModel
|
@@ -98,7 +98,7 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
|
|
98
98
|
record = define_model :example, attr: :string do
|
99
99
|
validates_length_of :attr, is: 40, allow_blank: true
|
100
100
|
end.new
|
101
|
-
expect(record).to
|
101
|
+
expect(record).to validate_length_of(:attr).is_equal_to(40)
|
102
102
|
end
|
103
103
|
|
104
104
|
def store_translations(options = {without: []})
|
@@ -153,6 +153,10 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
|
|
153
153
|
message = options.delete(:message)
|
154
154
|
type = options.delete(:type)
|
155
155
|
|
156
|
-
ActiveModel::Errors
|
156
|
+
expect_any_instance_of(ActiveModel::Errors).
|
157
|
+
to receive(:generate_message).
|
158
|
+
with(attribute, type, {}).
|
159
|
+
at_least(1).
|
160
|
+
and_return(message)
|
157
161
|
end
|
158
162
|
end
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher, type: :model do
|
4
4
|
if active_model_4_0?
|
5
5
|
def self.available_column_types
|
6
6
|
[
|
@@ -59,7 +59,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'provides the correct failure message' do
|
62
|
-
message = %{Expected errors to include "must be blank" when attr is set to "an arbitrary value"
|
62
|
+
message = %{Expected errors to include "must be blank" when attr is set to "an arbitrary value",\ngot no errors}
|
63
63
|
|
64
64
|
expect { expect(active_model_with(:attr)).to validate_absence_of(:attr) }.to fail_with_message(message)
|
65
65
|
end
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher do
|
3
|
+
describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher, type: :model do
|
4
4
|
context 'a model with an acceptance validation' do
|
5
5
|
it 'accepts when the attributes match' do
|
6
6
|
expect(validating_acceptance).to matcher
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher, type: :model do
|
4
|
+
include UnitTests::ConfirmationMatcherHelpers
|
5
|
+
|
6
|
+
context '#description' do
|
7
|
+
it 'states that the confirmation must match its base attribute' do
|
8
|
+
builder = builder_for_record_validating_confirmation
|
9
|
+
message = "require #{builder.confirmation_attribute} to match #{builder.attribute_to_confirm}"
|
10
|
+
matcher = described_class.new(builder.attribute_to_confirm)
|
11
|
+
expect(matcher.description).to eq(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when the model has a confirmation validation' do
|
16
|
+
it 'passes' do
|
17
|
+
builder = builder_for_record_validating_confirmation
|
18
|
+
expect(builder.record).
|
19
|
+
to validate_confirmation_of(builder.attribute_to_confirm)
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when a nil message is specified' do
|
23
|
+
it 'ignores it' do
|
24
|
+
builder = builder_for_record_validating_confirmation
|
25
|
+
expect(builder.record).
|
26
|
+
to validate_confirmation_of(builder.attribute_to_confirm).
|
27
|
+
with_message(nil)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when the model does not have a confirmation validation' do
|
33
|
+
it 'fails' do
|
34
|
+
model = define_model(:example, attribute_to_confirm: :string)
|
35
|
+
record = model.new
|
36
|
+
expect(record).not_to validate_confirmation_of(:attribute_to_confirm)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when both validation and matcher specify a custom message' do
|
41
|
+
it 'passes when the expected and actual messages match' do
|
42
|
+
builder = builder_for_record_validating_confirmation(message: 'custom')
|
43
|
+
expect(builder.record).
|
44
|
+
to validate_confirmation_of(builder.attribute_to_confirm).
|
45
|
+
with_message(/custom/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'fails when the expected and actual messages do not match' do
|
49
|
+
builder = builder_for_record_validating_confirmation(message: 'custom')
|
50
|
+
expect(builder.record).
|
51
|
+
not_to validate_confirmation_of(builder.attribute_to_confirm).
|
52
|
+
with_message(/wrong/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when the validation specifies a message via i18n' do
|
57
|
+
it 'passes' do
|
58
|
+
builder = builder_for_record_validating_confirmation_with_18n_message
|
59
|
+
expect(builder.record).
|
60
|
+
to validate_confirmation_of(builder.attribute_to_confirm)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb
RENAMED
@@ -1,12 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel do
|
3
|
+
describe Shoulda::Matchers::ActiveModel, type: :model do
|
4
4
|
describe '#ensure_exclusion_of' do
|
5
5
|
it 'is aliased to #validate_exclusion_of' do
|
6
|
-
matchers.
|
6
|
+
allow(matchers).to receive(:validate_exclusion_of)
|
7
7
|
|
8
8
|
silence_warnings do
|
9
9
|
matchers.ensure_exclusion_of(:attr)
|
10
|
+
expect(matchers).to have_received(:validate_exclusion_of).with(:attr)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -16,7 +17,7 @@ describe Shoulda::Matchers::ActiveModel do
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher do
|
20
|
+
describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :model do
|
20
21
|
context 'an attribute which must be excluded from a range' do
|
21
22
|
it 'accepts ensuring the correct range' do
|
22
23
|
expect(validating_exclusion(in: 2..5)).
|
data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb
RENAMED
@@ -1,12 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Shoulda::Matchers::ActiveModel do
|
3
|
+
describe Shoulda::Matchers::ActiveModel, type: :model do
|
4
4
|
describe '#ensure_inclusion_of' do
|
5
5
|
it 'is aliased to #validate_inclusion_of' do
|
6
|
-
matchers.
|
6
|
+
allow(matchers).to receive(:validate_inclusion_of)
|
7
7
|
|
8
8
|
silence_warnings do
|
9
9
|
matchers.ensure_inclusion_of(:attr)
|
10
|
+
expect(matchers).to have_received(:validate_inclusion_of)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -16,7 +17,7 @@ describe Shoulda::Matchers::ActiveModel do
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
20
|
+
describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher, type: :model do
|
20
21
|
shared_context 'for a generic attribute' do
|
21
22
|
def self.testing_values_of_option(option_name, &block)
|
22
23
|
[nil, true, false].each do |option_value|
|
@@ -188,8 +189,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
188
189
|
end
|
189
190
|
|
190
191
|
it 'does not match when validation uses the default message instead of given message' do
|
191
|
-
skip 'does not work'
|
192
|
-
|
193
192
|
builder = build_object_allowing(valid_values)
|
194
193
|
|
195
194
|
expect_not_to_match_on_values(builder, valid_values) do |matcher|
|
@@ -198,8 +197,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
198
197
|
end
|
199
198
|
|
200
199
|
it 'does not match when validation uses a message but it is not same as given' do
|
201
|
-
skip 'does not work'
|
202
|
-
|
203
200
|
builder = build_object_allowing(valid_values, message: 'a different message')
|
204
201
|
|
205
202
|
expect_not_to_match_on_values(builder, valid_values) do |matcher|
|
@@ -218,8 +215,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
218
215
|
end
|
219
216
|
|
220
217
|
it 'does not match when validation uses the default message instead of given message' do
|
221
|
-
skip 'does not work'
|
222
|
-
|
223
218
|
builder = build_object_allowing(valid_values)
|
224
219
|
|
225
220
|
expect_not_to_match_on_values(builder, valid_values) do |matcher|
|
@@ -228,8 +223,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
228
223
|
end
|
229
224
|
|
230
225
|
it 'does not match when validation uses a message but it does not match regex' do
|
231
|
-
skip 'does not work'
|
232
|
-
|
233
226
|
builder = build_object_allowing(valid_values, message: 'a different message')
|
234
227
|
|
235
228
|
expect_not_to_match_on_values(builder, valid_values) do |matcher|
|
@@ -444,7 +437,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
444
437
|
it 'matches' do
|
445
438
|
valid_values = [true, false]
|
446
439
|
builder = build_object_allowing(valid_values)
|
447
|
-
|
440
|
+
silence_stderr do
|
448
441
|
expect_to_match_in_array(builder, valid_values)
|
449
442
|
end
|
450
443
|
end
|
@@ -476,7 +469,7 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
|
|
476
469
|
it 'matches' do
|
477
470
|
valid_values = [nil]
|
478
471
|
builder = build_object_allowing(valid_values)
|
479
|
-
|
472
|
+
silence_stderr do
|
480
473
|
expect_to_match_in_array(builder, valid_values)
|
481
474
|
end
|
482
475
|
end
|