shoulda-matchers 4.4.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +22 -0
  3. data/README.md +18 -18
  4. data/lib/shoulda/matchers.rb +12 -13
  5. data/lib/shoulda/matchers/action_controller.rb +13 -13
  6. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -89
  7. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
  8. data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
  9. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +29 -27
  10. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
  11. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
  12. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
  13. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
  14. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
  15. data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
  16. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
  17. data/lib/shoulda/matchers/active_model.rb +25 -15
  18. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +29 -36
  19. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
  20. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
  22. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
  23. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
  24. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
  25. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
  26. data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
  27. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +0 -5
  28. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -34
  29. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
  30. data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
  31. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +10 -2
  32. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
  33. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +8 -7
  34. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +26 -25
  35. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +6 -6
  36. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +40 -27
  37. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
  38. data/lib/shoulda/matchers/active_model/validation_matcher.rb +6 -8
  39. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
  40. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
  41. data/lib/shoulda/matchers/active_model/validator.rb +4 -9
  42. data/lib/shoulda/matchers/active_record.rb +26 -14
  43. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
  44. data/lib/shoulda/matchers/active_record/association_matcher.rb +101 -48
  45. data/lib/shoulda/matchers/active_record/association_matchers.rb +0 -12
  46. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
  47. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
  48. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
  49. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
  50. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -9
  51. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +12 -7
  52. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
  53. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
  54. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
  55. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +4 -4
  56. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
  57. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
  58. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +18 -9
  59. data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +46 -8
  60. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +39 -17
  61. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  62. data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +7 -7
  63. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
  64. data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +11 -7
  65. data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +2 -0
  66. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
  67. data/lib/shoulda/matchers/active_record/uniqueness.rb +4 -4
  68. data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
  69. data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
  70. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +78 -71
  71. data/lib/shoulda/matchers/doublespeak.rb +9 -9
  72. data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
  73. data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
  74. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
  75. data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
  76. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
  77. data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
  78. data/lib/shoulda/matchers/error.rb +1 -1
  79. data/lib/shoulda/matchers/independent.rb +1 -0
  80. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -16
  81. data/lib/shoulda/matchers/integrations.rb +6 -6
  82. data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
  83. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
  84. data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
  85. data/lib/shoulda/matchers/integrations/test_frameworks.rb +2 -4
  86. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
  87. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
  88. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
  89. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
  90. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
  91. data/lib/shoulda/matchers/rails_shim.rb +5 -42
  92. data/lib/shoulda/matchers/util.rb +9 -2
  93. data/lib/shoulda/matchers/util/word_wrap.rb +7 -7
  94. data/lib/shoulda/matchers/version.rb +1 -1
  95. data/lib/shoulda/matchers/warn.rb +3 -3
  96. data/shoulda-matchers.gemspec +12 -9
  97. metadata +14 -14
  98. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
@@ -75,14 +75,12 @@ module Shoulda
75
75
  private
76
76
 
77
77
  def redirects_to_url?
78
- begin
79
- @context.__send__(:assert_redirected_to, url)
80
- @failure_message_when_negated = "Didn't expect to redirect to #{url}"
81
- true
82
- rescue Shoulda::Matchers.assertion_exception_class => error
83
- @failure_message = error.message
84
- false
85
- end
78
+ @context.__send__(:assert_redirected_to, url)
79
+ @failure_message_when_negated = "Didn't expect to redirect to #{url}"
80
+ true
81
+ rescue Shoulda::Matchers.assertion_exception_class => e
82
+ @failure_message = e.message
83
+ false
86
84
  end
87
85
 
88
86
  def url
@@ -71,14 +71,12 @@ module Shoulda
71
71
  private
72
72
 
73
73
  def renders_template?
74
- begin
75
- @context.__send__(:assert_template, @options, @message)
76
- @failure_message_when_negated = "Didn't expect to render #{@template}"
77
- true
78
- rescue Shoulda::Matchers.assertion_exception_class => error
79
- @failure_message = error.message
80
- false
81
- end
74
+ @context.__send__(:assert_template, @options, @message)
75
+ @failure_message_when_negated = "Didn't expect to render #{@template}"
76
+ true
77
+ rescue Shoulda::Matchers.assertion_exception_class => e
78
+ @failure_message = e.message
79
+ false
82
80
  end
83
81
  end
84
82
  end
@@ -64,12 +64,12 @@ module Shoulda
64
64
  # @private
65
65
  class RenderWithLayoutMatcher
66
66
  def initialize(expected_layout)
67
- if expected_layout
68
- @expected_layout = expected_layout.to_s
69
- else
70
- @expected_layout = nil
71
- end
72
-
67
+ @expected_layout =
68
+ if expected_layout
69
+ expected_layout.to_s
70
+ else
71
+ nil
72
+ end
73
73
  @controller = nil
74
74
  end
75
75
 
@@ -95,11 +95,12 @@ module Shoulda
95
95
 
96
96
  def description
97
97
  description = 'render with '
98
- if @expected_layout.nil?
99
- description << 'a layout'
100
- else
101
- description << "the #{@expected_layout.inspect} layout"
102
- end
98
+ description <<
99
+ if @expected_layout.nil?
100
+ 'a layout'
101
+ else
102
+ "the #{@expected_layout.inspect} layout"
103
+ end
103
104
  description
104
105
  end
105
106
 
@@ -118,7 +119,9 @@ module Shoulda
118
119
  end
119
120
 
120
121
  def rendered_layouts
121
- recorded_layouts.keys.compact.map { |layout| layout.sub(%r{^layouts/}, '') }
122
+ recorded_layouts.keys.compact.map { |layout|
123
+ layout.sub(%r{^layouts/}, '')
124
+ }
122
125
  end
123
126
 
124
127
  def recorded_layouts
@@ -135,7 +138,7 @@ module Shoulda
135
138
 
136
139
  def result
137
140
  if rendered_with_layout?
138
- 'rendered with ' + rendered_layouts.map(&:inspect).join(', ')
141
+ "rendered with #{rendered_layouts.map(&:inspect).join(', ')}"
139
142
  else
140
143
  'rendered without a layout'
141
144
  end
@@ -79,7 +79,8 @@ module Shoulda
79
79
  end
80
80
 
81
81
  unless handler_exists?
82
- expectation << " but #{controller} does not respond to #{expected_method}"
82
+ expectation << " but #{controller} does not respond to"\
83
+ " #{expected_method}"
83
84
  end
84
85
  expectation
85
86
  end
@@ -177,13 +177,12 @@ module Shoulda
177
177
 
178
178
  def add_port_to_path(path, port)
179
179
  if port
180
- "http://example.com:#{port}" + path
180
+ "https://example.com:#{port}" + path
181
181
  else
182
182
  path
183
183
  end
184
184
  end
185
185
 
186
-
187
186
  def guess_controller_if_necessary(controller)
188
187
  params[:controller] ||= controller.controller_path
189
188
  end
@@ -195,11 +194,11 @@ module Shoulda
195
194
  params,
196
195
  )
197
196
  true
198
- rescue ::ActionController::RoutingError => error
199
- @failure_message = error.message
197
+ rescue ::ActionController::RoutingError => e
198
+ @failure_message = e.message
200
199
  false
201
- rescue Shoulda::Matchers.assertion_exception_class => error
202
- @failure_message = error.message
200
+ rescue Shoulda::Matchers.assertion_exception_class => e
201
+ @failure_message = e.message
203
202
  false
204
203
  end
205
204
  end
@@ -3,7 +3,7 @@ module Shoulda
3
3
  module ActionController
4
4
  # @private
5
5
  class RouteParams
6
- PARAMS_TO_SYMBOLIZE = %i{ format }
6
+ PARAMS_TO_SYMBOLIZE = %i{format}.freeze
7
7
 
8
8
  def initialize(args)
9
9
  @args = args
@@ -20,7 +20,9 @@ module Shoulda
20
20
  def to(expected_value = nil, &block)
21
21
  if block
22
22
  unless context_set?
23
- message = "When specifying a value as a block, a context must be specified beforehand, e.g., #{store.name}.in_context(context).to { ... }"
23
+ message = 'When specifying a value as a block, a context must be'\
24
+ ' specified beforehand,'\
25
+ " e.g., #{store.name}.in_context(context).to { ... }"
24
26
  raise ArgumentError, message
25
27
  end
26
28
 
@@ -42,12 +44,14 @@ module Shoulda
42
44
  end
43
45
 
44
46
  def failure_message
45
- "Expected #{controller.class} to #{expectation_description}, but it did not"
47
+ "Expected #{controller.class} to #{expectation_description},"\
48
+ ' but it did not'
46
49
  end
47
50
  alias_method :failure_message_for_should, :failure_message
48
51
 
49
52
  def failure_message_when_negated
50
- "Expected #{controller.class} not to #{expectation_description}, but it did"
53
+ "Expected #{controller.class} not to #{expectation_description},"\
54
+ ' but it did'
51
55
  end
52
56
  alias_method :failure_message_for_should_not,
53
57
  :failure_message_when_negated
@@ -81,18 +85,20 @@ module Shoulda
81
85
  def expectation_description
82
86
  string = 'set'
83
87
 
84
- if key_set?
85
- string << " #{store.name}[#{key.inspect}]"
86
- else
87
- string << " any key in #{store.name}"
88
- end
89
-
90
- if expected_value_set?
91
- if expected_value.is_a?(Regexp)
92
- string << " to a value matching #{expected_value.inspect}"
88
+ string <<
89
+ if key_set?
90
+ " #{store.name}[#{key.inspect}]"
93
91
  else
94
- string << " to #{expected_value.inspect}"
92
+ " any key in #{store.name}"
95
93
  end
94
+
95
+ if expected_value_set?
96
+ string <<
97
+ if expected_value.is_a?(Regexp)
98
+ " to a value matching #{expected_value.inspect}"
99
+ else
100
+ " to #{expected_value.inspect}"
101
+ end
96
102
  end
97
103
 
98
104
  string
@@ -1,9 +1,33 @@
1
- require 'shoulda/matchers/active_model/allow_mass_assignment_of_matcher'
2
1
  require 'shoulda/matchers/active_model/helpers'
3
2
  require 'shoulda/matchers/active_model/qualifiers'
4
3
  require 'shoulda/matchers/active_model/validation_matcher'
4
+ require 'shoulda/matchers/active_model/validation_matcher/build_description'
5
+ require 'shoulda/matchers/active_model/validator'
6
+ require 'shoulda/matchers/active_model/allow_value_matcher'
7
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error'
8
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error'
9
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_setter'
10
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator'
11
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_setters'
12
+ require 'shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators'
13
+ require 'shoulda/matchers/active_model/allow_value_matcher/successful_check'
14
+ require 'shoulda/matchers/active_model/allow_value_matcher/successful_setting'
15
+ require 'shoulda/matchers/active_model/disallow_value_matcher'
16
+ require 'shoulda/matchers/active_model/validate_length_of_matcher'
17
+ require 'shoulda/matchers/active_model/validate_inclusion_of_matcher'
18
+ require 'shoulda/matchers/active_model/validate_exclusion_of_matcher'
5
19
  require 'shoulda/matchers/active_model/validate_absence_of_matcher'
6
20
  require 'shoulda/matchers/active_model/validate_presence_of_matcher'
21
+ require 'shoulda/matchers/active_model/validate_acceptance_of_matcher'
22
+ require 'shoulda/matchers/active_model/validate_confirmation_of_matcher'
23
+ require 'shoulda/matchers/active_model/validate_numericality_of_matcher'
24
+ require 'shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher'
25
+ require 'shoulda/matchers/active_model/numericality_matchers/comparison_matcher'
26
+ require 'shoulda/matchers/active_model/numericality_matchers/odd_number_matcher'
27
+ require 'shoulda/matchers/active_model/numericality_matchers/even_number_matcher'
28
+ require 'shoulda/matchers/active_model/numericality_matchers/only_integer_matcher'
29
+ require 'shoulda/matchers/active_model/errors'
30
+ require 'shoulda/matchers/active_model/have_secure_password_matcher'
7
31
 
8
32
  module Shoulda
9
33
  module Matchers
@@ -64,20 +88,6 @@ module Shoulda
64
88
  # end
65
89
  #
66
90
  module ActiveModel
67
- autoload :AllowValueMatcher, 'shoulda/matchers/active_model/allow_value_matcher'
68
- autoload :CouldNotDetermineValueOutsideOfArray, 'shoulda/matchers/active_model/errors'
69
- autoload :CouldNotSetPasswordError, 'shoulda/matchers/active_model/errors'
70
- autoload :DisallowValueMatcher, 'shoulda/matchers/active_model/disallow_value_matcher'
71
- autoload :HaveSecurePasswordMatcher, 'shoulda/matchers/active_model/have_secure_password_matcher'
72
- autoload :NonNullableBooleanError, 'shoulda/matchers/active_model/errors'
73
- autoload :NumericalityMatchers, 'shoulda/matchers/active_model/numericality_matchers'
74
- autoload :ValidateAcceptanceOfMatcher, 'shoulda/matchers/active_model/validate_acceptance_of_matcher'
75
- autoload :ValidateConfirmationOfMatcher, 'shoulda/matchers/active_model/validate_confirmation_of_matcher'
76
- autoload :ValidateExclusionOfMatcher, 'shoulda/matchers/active_model/validate_exclusion_of_matcher'
77
- autoload :ValidateInclusionOfMatcher, 'shoulda/matchers/active_model/validate_inclusion_of_matcher'
78
- autoload :ValidateLengthOfMatcher, 'shoulda/matchers/active_model/validate_length_of_matcher'
79
- autoload :ValidateNumericalityOfMatcher, 'shoulda/matchers/active_model/validate_numericality_of_matcher'
80
- autoload :Validator, 'shoulda/matchers/active_model/validator'
81
91
  end
82
92
  end
83
93
  end
@@ -18,14 +18,14 @@ module Shoulda
18
18
  #
19
19
  # # RSpec
20
20
  # RSpec.describe UserProfile, type: :model do
21
- # it { should allow_value('http://foo.com').for(:website_url) }
22
- # it { should allow_value('http://bar.com').for(:website_url) }
21
+ # it { should allow_value('https://foo.com').for(:website_url) }
22
+ # it { should allow_value('https://bar.com').for(:website_url) }
23
23
  # end
24
24
  #
25
25
  # # Minitest (Shoulda)
26
26
  # class UserProfileTest < ActiveSupport::TestCase
27
- # should allow_value('http://foo.com').for(:website_url)
28
- # should allow_value('http://bar.com').for(:website_url)
27
+ # should allow_value('https://foo.com').for(:website_url)
28
+ # should allow_value('https://bar.com').for(:website_url)
29
29
  # end
30
30
  #
31
31
  # You can also test multiple values in one go, if you like. In the
@@ -36,7 +36,7 @@ module Shoulda
36
36
  # # RSpec
37
37
  # RSpec.describe UserProfile, type: :model do
38
38
  # it do
39
- # should allow_values('http://foo.com', 'http://bar.com').
39
+ # should allow_values('https://foo.com', 'https://bar.com').
40
40
  # for(:website_url)
41
41
  # end
42
42
  #
@@ -48,7 +48,7 @@ module Shoulda
48
48
  #
49
49
  # # Minitest (Shoulda)
50
50
  # class UserProfileTest < ActiveSupport::TestCase
51
- # should allow_values('http://foo.com', 'http://bar.com/baz').
51
+ # should allow_values('https://foo.com', 'https://bar.com/baz').
52
52
  # for(:website_url)
53
53
  #
54
54
  # should_not allow_values('foo', 'buz').
@@ -305,15 +305,6 @@ module Shoulda
305
305
 
306
306
  # @private
307
307
  class AllowValueMatcher
308
- autoload :AttributeChangedValueError, 'shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error'
309
- autoload :AttributeDoesNotExistError, 'shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error'
310
- autoload :AttributeSetter, 'shoulda/matchers/active_model/allow_value_matcher/attribute_setter'
311
- autoload :AttributeSetterAndValidator, 'shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator'
312
- autoload :AttributeSetters, 'shoulda/matchers/active_model/allow_value_matcher/attribute_setters'
313
- autoload :AttributeSettersAndValidators, 'shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators'
314
- autoload :SuccessfulCheck, 'shoulda/matchers/active_model/allow_value_matcher/successful_check'
315
- autoload :SuccessfulSetting, 'shoulda/matchers/active_model/allow_value_matcher/successful_setting'
316
-
317
308
  include Helpers
318
309
  include Qualifiers::IgnoringInterferenceByWriter
319
310
 
@@ -322,7 +313,7 @@ module Shoulda
322
313
  :attribute_to_check_message_against,
323
314
  :attribute_to_set,
324
315
  :context,
325
- :instance
316
+ :instance,
326
317
  )
327
318
 
328
319
  attr_writer(
@@ -432,55 +423,56 @@ module Shoulda
432
423
  end
433
424
 
434
425
  if include_attribute_changed_value_message?
435
- message << "\n\n" + attribute_changed_value_message.call
426
+ message << "\n\n#{attribute_changed_value_message.call}"
436
427
  end
437
428
 
438
429
  Shoulda::Matchers.word_wrap(message)
439
430
  end
440
431
 
441
- def failure_message_when_negated
432
+ def failure_message_when_negated # rubocop:disable Metrics/MethodLength
442
433
  attribute_setter = result.attribute_setter
443
434
 
444
435
  if attribute_setter.unsuccessfully_checked?
445
436
  message = attribute_setter.failure_message
446
437
  else
447
438
  validator = result.validator
448
- message = failure_message_preface.call + ' invalid'
439
+ message = "#{failure_message_preface.call} invalid"
449
440
 
450
441
  if validator.type_of_message_matched?
451
442
  if validator.has_messages?
452
443
  message << ' and to'
453
444
 
454
- if validator.captured_validation_exception?
445
+ if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
455
446
  message << ' raise a validation exception with message'
456
447
  else
457
448
  message << ' produce'
458
449
 
459
- if expected_message.is_a?(Regexp)
460
- message << ' a'
461
- else
462
- message << ' the'
463
- end
450
+ message <<
451
+ if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
452
+ ' a'
453
+ else
454
+ ' the'
455
+ end
464
456
 
465
457
  message << ' validation error'
466
458
  end
467
459
 
468
- if expected_message.is_a?(Regexp)
460
+ if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
469
461
  message << ' matching '
470
462
  message << Shoulda::Matchers::Util.inspect_value(
471
- expected_message
463
+ expected_message,
472
464
  )
473
465
  else
474
466
  message << " #{expected_message.inspect}"
475
467
  end
476
468
 
477
- unless validator.captured_validation_exception?
469
+ unless validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
478
470
  message << " on :#{attribute_to_check_message_against}"
479
471
  end
480
472
 
481
473
  message << '. The record was indeed invalid, but'
482
474
 
483
- if validator.captured_validation_exception?
475
+ if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
484
476
  message << ' the exception message was '
485
477
  message << validator.validation_exception_message.inspect
486
478
  message << ' instead.'
@@ -501,7 +493,7 @@ module Shoulda
501
493
  end
502
494
 
503
495
  if include_attribute_changed_value_message?
504
- message << "\n\n" + attribute_changed_value_message.call
496
+ message << "\n\n#{attribute_changed_value_message.call}"
505
497
  end
506
498
 
507
499
  Shoulda::Matchers.word_wrap(message)
@@ -540,7 +532,8 @@ module Shoulda
540
532
 
541
533
  def run(strategy)
542
534
  attribute_setters_for_values_to_preset.first_failing ||
543
- attribute_setters_and_validators_for_values_to_set.public_send(strategy)
535
+ attribute_setters_and_validators_for_values_to_set.
536
+ public_send(strategy)
544
537
  end
545
538
 
546
539
  def failure_message_preface
@@ -606,14 +599,14 @@ pass, or do something else entirely.
606
599
  @_attribute_setters_and_validators_for_values_to_set ||=
607
600
  AttributeSettersAndValidators.new(
608
601
  self,
609
- values_to_set.map { |value| [attribute_to_set, value] }
602
+ values_to_set.map { |value| [attribute_to_set, value] },
610
603
  )
611
604
  end
612
605
 
613
606
  def inspected_values_to_set
614
607
  Shoulda::Matchers::Util.inspect_values(values_to_set).to_sentence(
615
- two_words_connector: " or ",
616
- last_word_connector: ", or "
608
+ two_words_connector: ' or ',
609
+ last_word_connector: ', or ',
617
610
  )
618
611
  end
619
612
 
@@ -628,7 +621,7 @@ pass, or do something else entirely.
628
621
  def default_attribute_message
629
622
  default_error_message(
630
623
  options[:expected_message],
631
- default_attribute_message_values
624
+ default_attribute_message_values,
632
625
  )
633
626
  end
634
627
 
@@ -648,7 +641,7 @@ pass, or do something else entirely.
648
641
 
649
642
  def human_attribute_name
650
643
  instance.class.human_attribute_name(
651
- attribute_to_check_message_against
644
+ attribute_to_check_message_against,
652
645
  )
653
646
  end
654
647
  end