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.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -3
  3. data/Appraisals +18 -0
  4. data/CONTRIBUTING.md +13 -29
  5. data/Gemfile +1 -4
  6. data/Gemfile.lock +2 -10
  7. data/NEWS.md +100 -14
  8. data/README.md +62 -58
  9. data/Rakefile +9 -16
  10. data/gemfiles/3.0.gemfile +11 -12
  11. data/gemfiles/3.0.gemfile.lock +15 -10
  12. data/gemfiles/3.1.gemfile +11 -12
  13. data/gemfiles/3.1.gemfile.lock +14 -10
  14. data/gemfiles/3.1_1.9.2.gemfile +12 -11
  15. data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
  16. data/gemfiles/3.2.gemfile +11 -12
  17. data/gemfiles/3.2.gemfile.lock +15 -10
  18. data/gemfiles/3.2_1.9.2.gemfile +12 -11
  19. data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
  20. data/gemfiles/4.0.0.gemfile +10 -12
  21. data/gemfiles/4.0.0.gemfile.lock +13 -10
  22. data/gemfiles/4.0.1.gemfile +10 -12
  23. data/gemfiles/4.0.1.gemfile.lock +13 -10
  24. data/gemfiles/4.1.gemfile +13 -15
  25. data/gemfiles/4.1.gemfile.lock +45 -50
  26. data/gemfiles/4.2.gemfile +36 -0
  27. data/gemfiles/4.2.gemfile.lock +245 -0
  28. data/lib/shoulda/matchers.rb +3 -1
  29. data/lib/shoulda/matchers/action_controller.rb +1 -1
  30. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
  32. data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
  33. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
  34. data/lib/shoulda/matchers/active_model.rb +1 -2
  35. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
  36. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
  37. data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
  38. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
  39. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
  40. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
  41. data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
  42. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
  43. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
  44. data/lib/shoulda/matchers/active_record.rb +2 -0
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
  46. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
  47. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
  48. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
  49. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
  50. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
  51. data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
  52. data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
  53. data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
  54. data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
  55. data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
  56. data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
  57. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
  58. data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
  59. data/lib/shoulda/matchers/matcher_context.rb +35 -0
  60. data/lib/shoulda/matchers/rails_shim.rb +23 -0
  61. data/lib/shoulda/matchers/util.rb +28 -0
  62. data/lib/shoulda/matchers/version.rb +1 -1
  63. data/script/SUPPORTED_VERSIONS +1 -1
  64. data/spec/acceptance/active_model_integration_spec.rb +20 -0
  65. data/spec/acceptance/independent_matchers_spec.rb +64 -0
  66. data/spec/acceptance/rails_integration_spec.rb +142 -0
  67. data/spec/acceptance_spec_helper.rb +23 -0
  68. data/spec/support/acceptance/helpers.rb +29 -0
  69. data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
  70. data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
  71. data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
  72. data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
  73. data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
  74. data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
  75. data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
  76. data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
  77. data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
  78. data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
  79. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
  80. data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
  81. data/spec/support/acceptance/matchers/have_output.rb +31 -0
  82. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
  83. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
  84. data/spec/support/tests/bundle.rb +94 -0
  85. data/spec/support/tests/command_runner.rb +214 -0
  86. data/spec/support/tests/filesystem.rb +77 -0
  87. data/spec/support/tests/version.rb +45 -0
  88. data/spec/support/unit/capture.rb +34 -0
  89. data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
  90. data/spec/support/unit/helpers/active_model_versions.rb +20 -0
  91. data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
  92. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
  93. data/spec/support/unit/helpers/class_builder.rb +72 -0
  94. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
  95. data/spec/support/unit/helpers/controller_builder.rb +91 -0
  96. data/spec/support/unit/helpers/i18n_faker.rb +15 -0
  97. data/spec/support/unit/helpers/mailer_builder.rb +12 -0
  98. data/spec/support/unit/helpers/model_builder.rb +102 -0
  99. data/spec/support/unit/helpers/rails_versions.rb +28 -0
  100. data/spec/support/unit/i18n.rb +7 -0
  101. data/spec/support/unit/matchers/deprecate.rb +60 -0
  102. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
  103. data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
  104. data/spec/support/unit/matchers/print_warning_including.rb +59 -0
  105. data/spec/support/unit/rails_application.rb +110 -0
  106. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
  107. data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
  108. data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
  109. data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
  110. data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
  111. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
  112. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
  113. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
  114. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
  115. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
  116. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
  117. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
  118. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
  119. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
  120. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
  121. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
  122. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
  123. data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
  124. data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
  125. data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
  126. data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
  127. data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
  128. data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
  129. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
  130. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
  131. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
  132. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
  133. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
  134. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
  135. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
  136. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
  137. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
  138. 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
  139. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
  140. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
  141. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
  142. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
  143. data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
  144. data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
  145. data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
  146. data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
  147. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
  148. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
  149. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
  150. data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
  151. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
  152. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
  153. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
  154. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
  155. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
  156. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
  157. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
  158. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
  159. data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
  160. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
  161. data/spec/unit_spec_helper.rb +66 -0
  162. data/spec/warnings_spy/partitioner.rb +10 -3
  163. data/spec/warnings_spy/reader.rb +9 -20
  164. data/spec/warnings_spy/reporter.rb +2 -1
  165. metadata +212 -149
  166. data/features/activemodel_integration.feature +0 -15
  167. data/features/rails_integration.feature +0 -160
  168. data/features/step_definitions/activemodel_steps.rb +0 -21
  169. data/features/step_definitions/rails_steps.rb +0 -227
  170. data/features/support/env.rb +0 -6
  171. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
  172. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
  173. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
  174. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
  175. data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
  176. data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
  177. data/spec/spec_helper.rb +0 -42
  178. data/spec/support/active_model_versions.rb +0 -13
  179. data/spec/support/active_resource_builder.rb +0 -29
  180. data/spec/support/activemodel_helpers.rb +0 -23
  181. data/spec/support/capture_helpers.rb +0 -19
  182. data/spec/support/class_builder.rb +0 -46
  183. data/spec/support/controller_builder.rb +0 -102
  184. data/spec/support/fail_with_message_including_matcher.rb +0 -44
  185. data/spec/support/fail_with_message_matcher.rb +0 -44
  186. data/spec/support/i18n_faker.rb +0 -10
  187. data/spec/support/mailer_builder.rb +0 -10
  188. data/spec/support/model_builder.rb +0 -81
  189. data/spec/support/rails_versions.rb +0 -26
  190. data/spec/support/test_application.rb +0 -120
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
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 = mock()
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 = mock()
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 = mock()
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 = mock()
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
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
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 'spec_helper'
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 'an attribute where the message occurs on another attribute' do
92
- it 'allows a good value' do
93
- expect(record_with_custom_validation).to \
94
- allow_value('good value').for(:attr).with_message(/some message/, against: :attr2)
95
- end
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
- it 'rejects a bad value' do
98
- expect(record_with_custom_validation).not_to \
99
- allow_value('bad value').for(:attr).with_message(/some message/, against: :attr2)
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
- def record_with_custom_validation
103
- define_model :example, attr: :string, attr2: :string do
104
- validate :custom_validation
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
- def custom_validation
107
- if self[:attr] != 'good value'
108
- self.errors[:attr2] << 'some message'
109
- end
110
- end
111
- end.new
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 'Expected exception to include /abc/ ' +
198
- 'when attr is set to "xyz", got Attr is invalid'
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 'spec_helper'
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 = stub_everything(failure_message_when_negated: 'allow matcher failure')
40
- Shoulda::Matchers::ActiveModel::AllowValueMatcher.stubs(:new).returns(allow_matcher)
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 'spec_helper'
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
 
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
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 'spec_helper'
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 ensure_length_of(:attr).is_equal_to(40)
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.any_instance.expects(:generate_message).with(attribute, type, {}).at_least_once.returns(message)
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
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'unit_spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::ComparisonMatcher do
4
4
  subject { described_class.new(matcher, 0, :>) }
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'unit_spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::EvenNumberMatcher do
4
4
  subject { described_class.new(:attr) }
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'unit_spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OddNumberMatcher do
4
4
  subject { described_class.new(:attr) }
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'unit_spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OnlyIntegerMatcher do
4
4
  subject { described_class.new(:attr) }
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
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", got no errors}
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
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
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
@@ -1,12 +1,13 @@
1
- require 'spec_helper'
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.expects(:validate_exclusion_of).with(:attr)
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)).
@@ -1,12 +1,13 @@
1
- require 'spec_helper'
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.expects(:validate_inclusion_of).with(:attr)
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
- capture(:stderr) do
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
- capture(:stderr) do
472
+ silence_stderr do
480
473
  expect_to_match_in_array(builder, valid_values)
481
474
  end
482
475
  end