shoulda-matchers 4.4.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +22 -0
- data/README.md +18 -18
- data/lib/shoulda/matchers.rb +12 -13
- data/lib/shoulda/matchers/action_controller.rb +13 -13
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -89
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +29 -27
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
- data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/active_model.rb +25 -15
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +29 -36
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
- data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers.rb +0 -5
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -34
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +10 -2
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +8 -7
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +26 -25
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +6 -6
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +40 -27
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +6 -8
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +4 -9
- data/lib/shoulda/matchers/active_record.rb +26 -14
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
- data/lib/shoulda/matchers/active_record/association_matcher.rb +101 -48
- data/lib/shoulda/matchers/active_record/association_matchers.rb +0 -12
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -9
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +12 -7
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +18 -9
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +46 -8
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +39 -17
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +7 -7
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +11 -7
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +2 -0
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
- data/lib/shoulda/matchers/active_record/uniqueness.rb +4 -4
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +78 -71
- data/lib/shoulda/matchers/doublespeak.rb +9 -9
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +1 -0
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -16
- data/lib/shoulda/matchers/integrations.rb +6 -6
- data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks.rb +2 -4
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +5 -42
- data/lib/shoulda/matchers/util.rb +9 -2
- data/lib/shoulda/matchers/util/word_wrap.rb +7 -7
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +3 -3
- data/shoulda-matchers.gemspec +12 -9
- metadata +14 -14
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
@@ -1,17 +1,10 @@
|
|
1
1
|
require 'forwardable'
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
module Shoulda
|
4
5
|
module Matchers
|
5
6
|
# @private
|
6
7
|
module Doublespeak
|
7
|
-
autoload :Double, 'shoulda/matchers/doublespeak/double'
|
8
|
-
autoload :DoubleCollection, 'shoulda/matchers/doublespeak/double_collection'
|
9
|
-
autoload :DoubleImplementationRegistry, 'shoulda/matchers/doublespeak/double_implementation_registry'
|
10
|
-
autoload :MethodCall, 'shoulda/matchers/doublespeak/method_call'
|
11
|
-
autoload :ObjectDouble, 'shoulda/matchers/doublespeak/object_double'
|
12
|
-
autoload :ProxyImplementation, 'shoulda/matchers/doublespeak/proxy_implementation'
|
13
|
-
autoload :World, 'shoulda/matchers/doublespeak/world'
|
14
|
-
|
15
8
|
class << self
|
16
9
|
extend Forwardable
|
17
10
|
|
@@ -28,7 +21,7 @@ module Shoulda
|
|
28
21
|
|
29
22
|
def debug(&block)
|
30
23
|
if debugging_enabled?
|
31
|
-
puts block.call
|
24
|
+
puts block.call # rubocop:disable Rails/Output
|
32
25
|
end
|
33
26
|
end
|
34
27
|
end
|
@@ -36,4 +29,11 @@ module Shoulda
|
|
36
29
|
end
|
37
30
|
end
|
38
31
|
|
32
|
+
require 'shoulda/matchers/doublespeak/double'
|
33
|
+
require 'shoulda/matchers/doublespeak/double_collection'
|
34
|
+
require 'shoulda/matchers/doublespeak/double_implementation_registry'
|
35
|
+
require 'shoulda/matchers/doublespeak/method_call'
|
36
|
+
require 'shoulda/matchers/doublespeak/object_double'
|
37
|
+
require 'shoulda/matchers/doublespeak/proxy_implementation'
|
39
38
|
require 'shoulda/matchers/doublespeak/stub_implementation'
|
39
|
+
require 'shoulda/matchers/doublespeak/world'
|
@@ -18,19 +18,19 @@ module Shoulda
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def activate
|
21
|
-
doubles_by_method_name.each do |
|
21
|
+
doubles_by_method_name.each do |_method_name, double|
|
22
22
|
double.activate
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def deactivate
|
27
|
-
doubles_by_method_name.each do |
|
27
|
+
doubles_by_method_name.each do |_method_name, double|
|
28
28
|
double.deactivate
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def calls_by_method_name
|
33
|
-
doubles_by_method_name.
|
33
|
+
doubles_by_method_name.inject({}) do |hash, (method_name, double)|
|
34
34
|
hash.merge method_name => double.calls.map(&:args)
|
35
35
|
end
|
36
36
|
end
|
@@ -4,23 +4,26 @@ module Shoulda
|
|
4
4
|
# @private
|
5
5
|
module DoubleImplementationRegistry
|
6
6
|
class << self
|
7
|
-
REGISTRY = {}
|
8
|
-
|
9
7
|
def find(type)
|
10
8
|
find_class!(type).create
|
11
9
|
end
|
12
10
|
|
13
11
|
def register(klass, type)
|
14
|
-
|
12
|
+
registry[type] = klass
|
15
13
|
end
|
16
14
|
|
17
15
|
private
|
18
16
|
|
19
17
|
def find_class!(type)
|
20
|
-
|
21
|
-
raise ArgumentError,
|
18
|
+
registry.fetch(type) do
|
19
|
+
raise ArgumentError, 'No double implementation class found for'\
|
20
|
+
" '#{type}'"
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
def registry
|
25
|
+
@_registry ||= {}
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -39,13 +39,13 @@ module Shoulda
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def activate
|
42
|
-
double_collections_by_class.each do |
|
42
|
+
double_collections_by_class.each do |_klass, double_collection|
|
43
43
|
double_collection.activate
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def deactivate
|
48
|
-
double_collections_by_class.each do |
|
48
|
+
double_collections_by_class.each do |_klass, double_collection|
|
49
49
|
double_collection.deactivate
|
50
50
|
end
|
51
51
|
end
|
@@ -176,9 +176,6 @@ module Shoulda
|
|
176
176
|
|
177
177
|
# @private
|
178
178
|
class DelegateMethodMatcher
|
179
|
-
autoload :StubbedTarget, 'shoulda/matchers/independent/delegate_method_matcher/stubbed_target'
|
180
|
-
autoload :DelegateObjectNotSpecified, 'shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error'
|
181
|
-
|
182
179
|
def initialize(delegating_method)
|
183
180
|
@delegating_method = delegating_method
|
184
181
|
|
@@ -222,9 +219,9 @@ module Shoulda
|
|
222
219
|
end
|
223
220
|
|
224
221
|
if expects_to_allow_nil_delegate_object?
|
225
|
-
string <<
|
222
|
+
string << ', allowing '
|
226
223
|
string << formatted_delegate_object_reader_method_name
|
227
|
-
string <<
|
224
|
+
string << ' to return nil'
|
228
225
|
end
|
229
226
|
|
230
227
|
string
|
@@ -248,7 +245,7 @@ module Shoulda
|
|
248
245
|
def with_prefix(prefix = nil)
|
249
246
|
@delegating_method =
|
250
247
|
:"#{build_delegating_method_prefix(prefix)}_#{delegate_method}"
|
251
|
-
|
248
|
+
delegate_method
|
252
249
|
self
|
253
250
|
end
|
254
251
|
|
@@ -259,8 +256,8 @@ module Shoulda
|
|
259
256
|
|
260
257
|
def build_delegating_method_prefix(prefix)
|
261
258
|
case prefix
|
262
|
-
|
263
|
-
|
259
|
+
when true, nil then delegate_object_reader_method
|
260
|
+
else prefix
|
264
261
|
end
|
265
262
|
end
|
266
263
|
|
@@ -347,7 +344,7 @@ module Shoulda
|
|
347
344
|
if options[:include_module]
|
348
345
|
class_under_test.to_s
|
349
346
|
else
|
350
|
-
|
347
|
+
''
|
351
348
|
end
|
352
349
|
end
|
353
350
|
|
@@ -401,11 +398,12 @@ module Shoulda
|
|
401
398
|
true
|
402
399
|
rescue Module::DelegationError
|
403
400
|
false
|
404
|
-
rescue NoMethodError =>
|
405
|
-
if
|
401
|
+
rescue NoMethodError => e
|
402
|
+
if e.message =~
|
403
|
+
/undefined method `#{delegate_method}' for nil:NilClass/
|
406
404
|
false
|
407
405
|
else
|
408
|
-
raise
|
406
|
+
raise e
|
409
407
|
end
|
410
408
|
end
|
411
409
|
else
|
@@ -442,17 +440,17 @@ module Shoulda
|
|
442
440
|
end
|
443
441
|
|
444
442
|
def formatted_calls_on_delegate_object
|
445
|
-
string =
|
443
|
+
string = ''
|
446
444
|
|
447
445
|
if calls_on_delegate_object.any?
|
448
446
|
string << "\n\n"
|
449
447
|
calls_on_delegate_object.each_with_index do |call, i|
|
450
448
|
name = call.method_name
|
451
|
-
args = call.args.map
|
452
|
-
string << "#{i+1}) #{name}(#{args})\n"
|
449
|
+
args = call.args.map(&:inspect).join(', ')
|
450
|
+
string << "#{i + 1}) #{name}(#{args})\n"
|
453
451
|
end
|
454
452
|
else
|
455
|
-
string <<
|
453
|
+
string << ' (none)'
|
456
454
|
end
|
457
455
|
|
458
456
|
string.rstrip!
|
@@ -2,12 +2,6 @@ module Shoulda
|
|
2
2
|
module Matchers
|
3
3
|
# @private
|
4
4
|
module Integrations
|
5
|
-
autoload :Configuration, 'shoulda/matchers/integrations/configuration'
|
6
|
-
autoload :ConfigurationError, 'shoulda/matchers/integrations/configuration_error'
|
7
|
-
autoload :Inclusion, 'shoulda/matchers/integrations/inclusion'
|
8
|
-
autoload :Rails, 'shoulda/matchers/integrations/rails'
|
9
|
-
autoload :Registry, 'shoulda/matchers/integrations/registry'
|
10
|
-
|
11
5
|
class << self
|
12
6
|
def register_library(klass, name)
|
13
7
|
library_registry.register(klass, name)
|
@@ -39,5 +33,11 @@ module Shoulda
|
|
39
33
|
end
|
40
34
|
end
|
41
35
|
|
36
|
+
require 'shoulda/matchers/integrations/configuration'
|
37
|
+
require 'shoulda/matchers/integrations/configuration_error'
|
38
|
+
require 'shoulda/matchers/integrations/inclusion'
|
39
|
+
require 'shoulda/matchers/integrations/rails'
|
40
|
+
require 'shoulda/matchers/integrations/registry'
|
41
|
+
|
42
42
|
require 'shoulda/matchers/integrations/libraries'
|
43
43
|
require 'shoulda/matchers/integrations/test_frameworks'
|
@@ -1,17 +1,15 @@
|
|
1
|
+
require 'shoulda/matchers/integrations/test_frameworks/active_support_test_case'
|
1
2
|
require 'shoulda/matchers/integrations/test_frameworks/minitest_4'
|
2
3
|
require 'shoulda/matchers/integrations/test_frameworks/minitest_5'
|
3
4
|
require 'shoulda/matchers/integrations/test_frameworks/missing_test_framework'
|
4
5
|
require 'shoulda/matchers/integrations/test_frameworks/rspec'
|
6
|
+
require 'shoulda/matchers/integrations/test_frameworks/test_unit'
|
5
7
|
|
6
8
|
module Shoulda
|
7
9
|
module Matchers
|
8
10
|
module Integrations
|
9
11
|
# @private
|
10
12
|
module TestFrameworks
|
11
|
-
autoload :ActiveSupportTestCase, 'shoulda/matchers/integrations/test_frameworks/active_support_test_case'
|
12
|
-
autoload :Minitest4, 'shoulda/matchers/integrations/test_frameworks/minitest_4'
|
13
|
-
autoload :Minitest5, 'shoulda/matchers/integrations/test_frameworks/minitest_5'
|
14
|
-
autoload :TestUnit, 'shoulda/matchers/integrations/test_frameworks/test_unit'
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -1,26 +1,14 @@
|
|
1
1
|
module Shoulda
|
2
2
|
module Matchers
|
3
3
|
# @private
|
4
|
-
module RailsShim
|
4
|
+
module RailsShim # rubocop:disable Metrics/ModuleLength
|
5
5
|
class << self
|
6
|
-
def action_pack_gte_5?
|
7
|
-
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
8
|
-
end
|
9
|
-
|
10
|
-
def action_pack_lt_5?
|
11
|
-
Gem::Requirement.new('< 5').satisfied_by?(action_pack_version)
|
12
|
-
end
|
13
|
-
|
14
6
|
def action_pack_version
|
15
7
|
Gem::Version.new(::ActionPack::VERSION::STRING)
|
16
8
|
rescue NameError
|
17
9
|
Gem::Version.new('0')
|
18
10
|
end
|
19
11
|
|
20
|
-
def active_record_gte_5?
|
21
|
-
Gem::Requirement.new('>= 5').satisfied_by?(active_record_version)
|
22
|
-
end
|
23
|
-
|
24
12
|
def active_record_gte_6?
|
25
13
|
Gem::Requirement.new('>= 6').satisfied_by?(active_record_version)
|
26
14
|
end
|
@@ -57,17 +45,6 @@ module Shoulda
|
|
57
45
|
)
|
58
46
|
end
|
59
47
|
|
60
|
-
def make_controller_request(context, verb, action, request_params)
|
61
|
-
params =
|
62
|
-
if action_pack_gte_5?
|
63
|
-
{ params: request_params }
|
64
|
-
else
|
65
|
-
request_params
|
66
|
-
end
|
67
|
-
|
68
|
-
context.__send__(verb, action, params)
|
69
|
-
end
|
70
|
-
|
71
48
|
def serialized_attributes_for(model)
|
72
49
|
attribute_types_for(model).
|
73
50
|
inject({}) do |hash, (attribute_name, attribute_type)|
|
@@ -85,26 +62,10 @@ module Shoulda
|
|
85
62
|
serialized_attributes_for(model)[attribute_name.to_s]
|
86
63
|
end
|
87
64
|
|
88
|
-
def tables_and_views(connection)
|
89
|
-
if active_record_gte_5?
|
90
|
-
connection.data_sources
|
91
|
-
else
|
92
|
-
connection.tables
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
65
|
def verb_for_update
|
97
66
|
:patch
|
98
67
|
end
|
99
68
|
|
100
|
-
def validation_message_key_for_association_required_option
|
101
|
-
if active_record_gte_5?
|
102
|
-
:required
|
103
|
-
else
|
104
|
-
:blank
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
69
|
def parent_of(mod)
|
109
70
|
if mod.respond_to?(:module_parent)
|
110
71
|
mod.module_parent
|
@@ -180,10 +141,12 @@ module Shoulda
|
|
180
141
|
options
|
181
142
|
)
|
182
143
|
default_translation_keys = [
|
183
|
-
:"activemodel.errors.models.#{model_name}.attributes.#{attribute}
|
144
|
+
:"activemodel.errors.models.#{model_name}.attributes.#{attribute}
|
145
|
+
.#{type}",
|
184
146
|
:"activemodel.errors.models.#{model_name}.#{type}",
|
185
147
|
:"activemodel.errors.messages.#{type}",
|
186
|
-
:"activerecord.errors.models.#{model_name}.attributes.#{attribute}
|
148
|
+
:"activerecord.errors.models.#{model_name}.attributes.#{attribute}
|
149
|
+
.#{type}",
|
187
150
|
:"activerecord.errors.models.#{model_name}.#{type}",
|
188
151
|
:"activerecord.errors.messages.#{type}",
|
189
152
|
:"errors.attributes.#{attribute}.#{type}",
|