shoulda-matchers 3.1.3 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.hound/ruby.yml +336 -316
  3. data/.python-version +1 -0
  4. data/.rubocop.yml +3 -1
  5. data/.travis.yml +7 -6
  6. data/Appraisals +76 -44
  7. data/CONTRIBUTING.md +137 -66
  8. data/Gemfile +5 -5
  9. data/Gemfile.lock +30 -35
  10. data/MAINTAINING.md +250 -0
  11. data/MIT-LICENSE +1 -1
  12. data/NEWS.md +176 -4
  13. data/README.md +138 -200
  14. data/Rakefile +7 -0
  15. data/bin/setup +190 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +4 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -6
  18. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -17
  19. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +27 -0
  20. data/gemfiles/4.2.gemfile +21 -20
  21. data/gemfiles/4.2.gemfile.lock +143 -140
  22. data/gemfiles/5.0.gemfile +37 -0
  23. data/gemfiles/5.0.gemfile.lock +238 -0
  24. data/gemfiles/5.1.gemfile +38 -0
  25. data/gemfiles/5.1.gemfile.lock +254 -0
  26. data/gemfiles/5.2.gemfile +40 -0
  27. data/gemfiles/5.2.gemfile.lock +273 -0
  28. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +18 -6
  29. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +6 -1
  30. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_matcher.rb +87 -27
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +1 -0
  33. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +0 -4
  34. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +5 -0
  35. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +5 -0
  36. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +26 -11
  37. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +39 -4
  38. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +116 -47
  39. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +127 -38
  40. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +55 -37
  41. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +30 -1
  42. data/lib/shoulda/matchers/active_model/validation_matcher.rb +11 -4
  43. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +11 -6
  44. data/lib/shoulda/matchers/active_record.rb +3 -0
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +172 -22
  46. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
  47. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +11 -6
  48. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +46 -0
  49. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +51 -0
  50. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +268 -38
  51. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  52. data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +111 -0
  53. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +207 -79
  54. data/lib/shoulda/matchers/doublespeak/object_double.rb +5 -1
  55. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +100 -21
  56. data/lib/shoulda/matchers/rails_shim.rb +133 -52
  57. data/lib/shoulda/matchers/routing.rb +2 -2
  58. data/lib/shoulda/matchers/util.rb +23 -1
  59. data/lib/shoulda/matchers/util/word_wrap.rb +6 -2
  60. data/lib/shoulda/matchers/version.rb +1 -1
  61. data/script/install_gems_in_all_appraisals +3 -1
  62. data/script/run_all_tests +3 -1
  63. data/script/supported_ruby_versions +7 -0
  64. data/script/update_gem_in_all_appraisals +3 -1
  65. data/script/update_gems_in_all_appraisals +3 -1
  66. data/shoulda-matchers.gemspec +3 -3
  67. data/spec/acceptance/independent_matchers_spec.rb +2 -2
  68. data/spec/acceptance/multiple_libraries_integration_spec.rb +1 -1
  69. data/spec/acceptance/rails_integration_spec.rb +2 -2
  70. data/spec/spec_helper.rb +2 -3
  71. data/spec/support/acceptance/helpers.rb +2 -0
  72. data/spec/support/acceptance/helpers/command_helpers.rb +17 -4
  73. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +21 -0
  74. data/spec/support/acceptance/helpers/step_helpers.rb +1 -1
  75. data/spec/support/tests/current_bundle.rb +3 -9
  76. data/spec/support/tests/filesystem.rb +2 -2
  77. data/spec/support/unit/attribute.rb +0 -2
  78. data/spec/support/unit/capture.rb +9 -3
  79. data/spec/support/unit/helpers/action_pack_versions.rb +22 -0
  80. data/spec/support/unit/helpers/active_model_versions.rb +4 -0
  81. data/spec/support/unit/helpers/active_record_versions.rb +22 -2
  82. data/spec/support/unit/helpers/active_resource_builder.rb +2 -2
  83. data/spec/support/unit/helpers/controller_builder.rb +1 -1
  84. data/spec/support/unit/helpers/message_helpers.rb +19 -0
  85. data/spec/support/unit/helpers/rails_versions.rb +14 -0
  86. data/spec/support/unit/matchers/fail_with_message_matcher.rb +7 -5
  87. data/spec/support/unit/matchers/print_warning_including.rb +21 -13
  88. data/spec/support/unit/model_creation_strategies/active_record.rb +1 -1
  89. data/spec/support/unit/model_creators/active_record.rb +0 -1
  90. data/spec/support/unit/model_creators/basic.rb +7 -2
  91. data/spec/support/unit/rails_application.rb +25 -0
  92. data/spec/support/unit/record_validating_confirmation_builder.rb +5 -2
  93. data/spec/support/unit/validation_matcher_scenario.rb +0 -2
  94. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +18 -18
  95. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +33 -5
  96. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +1 -1
  97. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +80 -78
  98. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +7 -9
  99. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +28 -4
  100. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +19 -1
  101. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +27 -4
  102. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +62 -5
  103. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +52 -18
  104. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +51 -4
  105. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +99 -71
  106. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +41 -15
  107. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +445 -15
  108. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +615 -93
  109. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +169 -0
  110. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +167 -97
  111. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +2 -4
  112. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +152 -19
  113. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +258 -94
  114. data/spec/unit_spec_helper.rb +9 -1
  115. data/zeus.json +1 -1
  116. metadata +31 -16
  117. data/gemfiles/4.0.0.gemfile +0 -38
  118. data/gemfiles/4.0.0.gemfile.lock +0 -223
  119. data/gemfiles/4.0.1.gemfile +0 -38
  120. data/gemfiles/4.0.1.gemfile.lock +0 -225
  121. data/gemfiles/4.1.gemfile +0 -38
  122. data/gemfiles/4.1.gemfile.lock +0 -220
  123. data/script/SUPPORTED_VERSIONS +0 -1
@@ -138,7 +138,8 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
138
138
  attribute_name: :attr,
139
139
  changing_values_with: :numeric_value,
140
140
  expected_message: <<-MESSAGE.strip
141
- Example did not properly validate that :attr looks like a number.
141
+ Expected Example to validate that :attr looks like a number, but this
142
+ could not be proved.
142
143
  After setting :attr to ‹"abcd"› -- which was read back as ‹"1"› -- the
143
144
  matcher expected the Example to be invalid, but it was valid instead.
144
145
 
@@ -188,6 +189,27 @@ Example did not properly validate that :attr looks like a number.
188
189
  end
189
190
  end
190
191
  end
192
+
193
+ context 'when used in the negative' do
194
+ it 'fails' do
195
+ assertion = lambda do
196
+ record = build_record_validating_numericality
197
+ expect(record).not_to validate_numericality
198
+ end
199
+
200
+ message = <<-MESSAGE
201
+ Expected Example not to validate that :attr looks like a number, but
202
+ this could not be proved.
203
+ After setting :attr to ‹"abcd"›, the matcher expected the Example to
204
+ be valid, but it was invalid instead, producing these validation
205
+ errors:
206
+
207
+ * attr: ["is not a number"]
208
+ MESSAGE
209
+
210
+ expect(&assertion).to fail_with_message(message)
211
+ end
212
+ end
191
213
  end
192
214
 
193
215
  context 'and not validating anything' do
@@ -197,7 +219,8 @@ Example did not properly validate that :attr looks like a number.
197
219
  assertion = -> { expect(record).to validate_numericality }
198
220
 
199
221
  message = <<-MESSAGE
200
- Example did not properly validate that :attr looks like a number.
222
+ Expected Example to validate that :attr looks like a number, but this
223
+ could not be proved.
201
224
  After setting :attr to ‹"abcd"›, the matcher expected the Example to
202
225
  be invalid, but it was valid instead.
203
226
  MESSAGE
@@ -225,8 +248,8 @@ Example did not properly validate that :attr looks like a number.
225
248
  attribute_name: :attr,
226
249
  changing_values_with: :next_value_or_non_numeric_value,
227
250
  expected_message: <<-MESSAGE.strip
228
- Example did not properly validate that :attr looks like a number, but
229
- only if it is not nil.
251
+ Expected Example to validate that :attr looks like a number as long as
252
+ it is not nil, but this could not be proved.
230
253
  In checking that Example allows :attr to be ‹nil›, after setting :attr
231
254
  to ‹nil› -- which was read back as ‹"a"› -- the matcher expected the
232
255
  Example to be valid, but it was invalid instead, producing these
@@ -262,8 +285,8 @@ only if it is not nil.
262
285
  end
263
286
 
264
287
  message = <<-MESSAGE
265
- Example did not properly validate that :attr looks like a number, but
266
- only if it is not nil.
288
+ Expected Example to validate that :attr looks like a number as long as
289
+ it is not nil, but this could not be proved.
267
290
  In checking that Example allows :attr to be ‹nil›, after setting :attr
268
291
  to ‹nil›, the matcher expected the Example to be valid, but it was
269
292
  invalid instead, producing these validation errors:
@@ -294,7 +317,8 @@ only if it is not nil.
294
317
  attribute_name: :attr,
295
318
  changing_values_with: :numeric_value,
296
319
  expected_message: <<-MESSAGE.strip
297
- Example did not properly validate that :attr looks like an integer.
320
+ Expected Example to validate that :attr looks like an integer, but this
321
+ could not be proved.
298
322
  After setting :attr to ‹"0.1"› -- which was read back as ‹"1"› -- the
299
323
  matcher expected the Example to be invalid, but it was valid instead.
300
324
 
@@ -326,7 +350,8 @@ Example did not properly validate that :attr looks like an integer.
326
350
  end
327
351
 
328
352
  message = <<-MESSAGE
329
- Example did not properly validate that :attr looks like an integer.
353
+ Expected Example to validate that :attr looks like an integer, but this
354
+ could not be proved.
330
355
  After setting :attr to ‹"0.1"›, the matcher expected the Example to be
331
356
  invalid, but it was valid instead.
332
357
  MESSAGE
@@ -354,7 +379,8 @@ Example did not properly validate that :attr looks like an integer.
354
379
  attribute_name: :attr,
355
380
  changing_values_with: :next_value,
356
381
  expected_message: <<-MESSAGE.strip
357
- Example did not properly validate that :attr looks like an odd number.
382
+ Expected Example to validate that :attr looks like an odd number, but
383
+ this could not be proved.
358
384
  After setting :attr to ‹"2"› -- which was read back as ‹"3"› -- the
359
385
  matcher expected the Example to be invalid, but it was valid instead.
360
386
 
@@ -428,7 +454,8 @@ Example did not properly validate that :attr looks like an odd number.
428
454
  end
429
455
 
430
456
  message = <<-MESSAGE
431
- Example did not properly validate that :attr looks like an odd number.
457
+ Expected Example to validate that :attr looks like an odd number, but
458
+ this could not be proved.
432
459
  After setting :attr to ‹"2"›, the matcher expected the Example to be
433
460
  invalid, but it was valid instead.
434
461
  MESSAGE
@@ -456,7 +483,8 @@ Example did not properly validate that :attr looks like an odd number.
456
483
  attribute_name: :attr,
457
484
  changing_values_with: :next_value,
458
485
  expected_message: <<-MESSAGE.strip
459
- Example did not properly validate that :attr looks like an even number.
486
+ Expected Example to validate that :attr looks like an even number, but
487
+ this could not be proved.
460
488
  After setting :attr to ‹"1"› -- which was read back as ‹"2"› -- the
461
489
  matcher expected the Example to be invalid, but it was valid instead.
462
490
 
@@ -530,7 +558,8 @@ Example did not properly validate that :attr looks like an even number.
530
558
  end
531
559
 
532
560
  message = <<-MESSAGE
533
- Example did not properly validate that :attr looks like an even number.
561
+ Expected Example to validate that :attr looks like an even number, but
562
+ this could not be proved.
534
563
  After setting :attr to ‹"1"›, the matcher expected the Example to be
535
564
  invalid, but it was valid instead.
536
565
  MESSAGE
@@ -557,8 +586,8 @@ Example did not properly validate that :attr looks like an even number.
557
586
  attribute_name: :attr,
558
587
  changing_values_with: :next_value,
559
588
  expected_message: <<-MESSAGE.strip
560
- Example did not properly validate that :attr looks like a number less
561
- than or equal to 18.
589
+ Expected Example to validate that :attr looks like a number less than or
590
+ equal to 18, but this could not be proved.
562
591
  After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
563
592
  matcher expected the Example to be valid, but it was invalid instead,
564
593
  producing these validation errors:
@@ -637,8 +666,8 @@ than or equal to 18.
637
666
  end
638
667
 
639
668
  message = <<-MESSAGE
640
- Example did not properly validate that :attr looks like a number less
641
- than or equal to 18.
669
+ Expected Example to validate that :attr looks like a number less than or
670
+ equal to 18, but this could not be proved.
642
671
  After setting :attr to ‹"19"›, the matcher expected the Example to be
643
672
  invalid, but it was valid instead.
644
673
  MESSAGE
@@ -665,8 +694,8 @@ than or equal to 18.
665
694
  attribute_name: :attr,
666
695
  changing_values_with: :next_value,
667
696
  expected_message: <<-MESSAGE.strip
668
- Example did not properly validate that :attr looks like a number less
669
- than 18.
697
+ Expected Example to validate that :attr looks like a number less than
698
+ 18, but this could not be proved.
670
699
  After setting :attr to ‹"17"› -- which was read back as ‹"18"› -- the
671
700
  matcher expected the Example to be valid, but it was invalid instead,
672
701
  producing these validation errors:
@@ -743,8 +772,8 @@ than 18.
743
772
  end
744
773
 
745
774
  message = <<-MESSAGE
746
- Example did not properly validate that :attr looks like a number less
747
- than 18.
775
+ Expected Example to validate that :attr looks like a number less than
776
+ 18, but this could not be proved.
748
777
  After setting :attr to ‹"19"›, the matcher expected the Example to be
749
778
  invalid, but it was valid instead.
750
779
  MESSAGE
@@ -769,8 +798,8 @@ than 18.
769
798
  attribute_name: :attr,
770
799
  changing_values_with: :next_value,
771
800
  expected_message: <<-MESSAGE.strip
772
- Example did not properly validate that :attr looks like a number equal
773
- to 18.
801
+ Expected Example to validate that :attr looks like a number equal to 18,
802
+ but this could not be proved.
774
803
  After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
775
804
  matcher expected the Example to be valid, but it was invalid instead,
776
805
  producing these validation errors:
@@ -847,8 +876,8 @@ to 18.
847
876
  end
848
877
 
849
878
  message = <<-MESSAGE
850
- Example did not properly validate that :attr looks like a number equal
851
- to 18.
879
+ Expected Example to validate that :attr looks like a number equal to 18,
880
+ but this could not be proved.
852
881
  After setting :attr to ‹"19"›, the matcher expected the Example to be
853
882
  invalid, but it was valid instead.
854
883
  MESSAGE
@@ -877,8 +906,8 @@ to 18.
877
906
  attribute_name: :attr,
878
907
  changing_values_with: :next_value,
879
908
  expected_message: <<-MESSAGE.strip
880
- Example did not properly validate that :attr looks like a number greater
881
- than or equal to 18.
909
+ Expected Example to validate that :attr looks like a number greater than
910
+ or equal to 18, but this could not be proved.
882
911
  After setting :attr to ‹"17"› -- which was read back as ‹"18"› -- the
883
912
  matcher expected the Example to be invalid, but it was valid instead.
884
913
 
@@ -962,8 +991,8 @@ than or equal to 18.
962
991
  end
963
992
 
964
993
  message = <<-MESSAGE
965
- Example did not properly validate that :attr looks like a number greater
966
- than or equal to 18.
994
+ Expected Example to validate that :attr looks like a number greater than
995
+ or equal to 18, but this could not be proved.
967
996
  After setting :attr to ‹"17"›, the matcher expected the Example to be
968
997
  invalid, but it was valid instead.
969
998
  MESSAGE
@@ -990,8 +1019,8 @@ than or equal to 18.
990
1019
  attribute_name: :attr,
991
1020
  changing_values_with: :next_value,
992
1021
  expected_message: <<-MESSAGE.strip
993
- Example did not properly validate that :attr looks like a number greater
994
- than 18.
1022
+ Expected Example to validate that :attr looks like a number greater than
1023
+ 18, but this could not be proved.
995
1024
  After setting :attr to ‹"18"› -- which was read back as ‹"19"› -- the
996
1025
  matcher expected the Example to be invalid, but it was valid instead.
997
1026
 
@@ -1071,8 +1100,8 @@ than 18.
1071
1100
  end
1072
1101
 
1073
1102
  message = <<-MESSAGE
1074
- Example did not properly validate that :attr looks like a number greater
1075
- than 18.
1103
+ Expected Example to validate that :attr looks like a number greater than
1104
+ 18, but this could not be proved.
1076
1105
  After setting :attr to ‹"18"›, the matcher expected the Example to be
1077
1106
  invalid, but it was valid instead.
1078
1107
  MESSAGE
@@ -1099,8 +1128,8 @@ than 18.
1099
1128
  end
1100
1129
 
1101
1130
  message = <<-MESSAGE
1102
- Example did not properly validate that :attr looks like a number,
1103
- producing a custom validation error on failure.
1131
+ Expected Example to validate that :attr looks like a number, producing a
1132
+ custom validation error on failure, but this could not be proved.
1104
1133
  After setting :attr to ‹"abcd"›, the matcher expected the Example to
1105
1134
  be invalid and to produce a validation error matching ‹/wrong/› on
1106
1135
  :attr. The record was indeed invalid, but it produced these validation
@@ -1129,8 +1158,8 @@ producing a custom validation error on failure.
1129
1158
  end
1130
1159
 
1131
1160
  message = <<-MESSAGE
1132
- Example did not properly validate that :attr looks like a number,
1133
- producing a custom validation error on failure.
1161
+ Expected Example to validate that :attr looks like a number, producing a
1162
+ custom validation error on failure, but this could not be proved.
1134
1163
  After setting :attr to ‹"abcd"›, the matcher expected the Example to
1135
1164
  be invalid, but it was valid instead.
1136
1165
  MESSAGE
@@ -1157,8 +1186,8 @@ producing a custom validation error on failure.
1157
1186
  end
1158
1187
 
1159
1188
  message = <<-MESSAGE
1160
- Example did not properly validate that :attr looks like a number,
1161
- raising a validation exception on failure.
1189
+ Expected Example to validate that :attr looks like a number, raising a
1190
+ validation exception on failure, but this could not be proved.
1162
1191
  After setting :attr to ‹"abcd"›, the matcher expected the Example to
1163
1192
  be invalid and to raise a validation exception, but the record
1164
1193
  produced validation errors instead.
@@ -1192,7 +1221,8 @@ raising a validation exception on failure.
1192
1221
  end
1193
1222
 
1194
1223
  message = <<-MESSAGE
1195
- Example did not properly validate that :attr looks like a number.
1224
+ Expected Example to validate that :attr looks like a number, but this
1225
+ could not be proved.
1196
1226
  After setting :attr to ‹"abcd"›, the matcher expected the Example to
1197
1227
  be invalid, but it was valid instead.
1198
1228
  MESSAGE
@@ -1229,8 +1259,8 @@ Example did not properly validate that :attr looks like a number.
1229
1259
  end
1230
1260
 
1231
1261
  message = <<-MESSAGE
1232
- Example did not properly validate that :attr looks like an integer
1233
- greater than 18.
1262
+ Expected Example to validate that :attr looks like an integer greater
1263
+ than 18, but this could not be proved.
1234
1264
  In checking that Example disallows :attr from being a decimal number,
1235
1265
  after setting :attr to ‹"0.1"›, the matcher expected the Example to be
1236
1266
  invalid and to produce the validation error "must be an integer" on
@@ -1254,8 +1284,8 @@ greater than 18.
1254
1284
  end
1255
1285
 
1256
1286
  message = <<-MESSAGE.strip_heredoc
1257
- Example did not properly validate that :attr looks like an integer
1258
- greater than 18.
1287
+ Expected Example to validate that :attr looks like an integer greater
1288
+ than 18, but this could not be proved.
1259
1289
  In checking that Example disallows :attr from being a decimal number,
1260
1290
  after setting :attr to ‹"0.1"›, the matcher expected the Example to be
1261
1291
  invalid and to produce the validation error "must be an integer" on
@@ -1282,8 +1312,8 @@ greater than 18.
1282
1312
  end
1283
1313
 
1284
1314
  message = <<-MESSAGE
1285
- Example did not properly validate that :attr looks like an even number
1286
- greater than 18.
1315
+ Expected Example to validate that :attr looks like an even number
1316
+ greater than 18, but this could not be proved.
1287
1317
  In checking that Example disallows :attr from being a number that is
1288
1318
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1289
1319
  expected the Example to be invalid, but it was valid instead.
@@ -1306,8 +1336,8 @@ greater than 18.
1306
1336
  end
1307
1337
 
1308
1338
  message = <<-MESSAGE
1309
- Example did not properly validate that :attr looks like an even number
1310
- greater than 18.
1339
+ Expected Example to validate that :attr looks like an even number
1340
+ greater than 18, but this could not be proved.
1311
1341
  In checking that Example disallows :attr from being an odd number,
1312
1342
  after setting :attr to ‹"1"›, the matcher expected the Example to be
1313
1343
  invalid and to produce the validation error "must be even" on :attr.
@@ -1334,8 +1364,8 @@ greater than 18.
1334
1364
  end
1335
1365
 
1336
1366
  message = <<-MESSAGE
1337
- Example did not properly validate that :attr looks like an odd number
1338
- less than or equal to 99.
1367
+ Expected Example to validate that :attr looks like an odd number less
1368
+ than or equal to 99, but this could not be proved.
1339
1369
  In checking that Example disallows :attr from being a number that is
1340
1370
  not less than or equal to 99, after setting :attr to ‹"101"›, the
1341
1371
  matcher expected the Example to be invalid, but it was valid instead.
@@ -1360,8 +1390,8 @@ less than or equal to 99.
1360
1390
  end
1361
1391
 
1362
1392
  message = <<-MESSAGE
1363
- Example did not properly validate that :attr looks like an integer
1364
- greater than 18 and less than 99.
1393
+ Expected Example to validate that :attr looks like an integer greater
1394
+ than 18 and less than 99, but this could not be proved.
1365
1395
  In checking that Example disallows :attr from being a number that is
1366
1396
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1367
1397
  expected the Example to be invalid, but it was valid instead.
@@ -1385,10 +1415,9 @@ greater than 18 and less than 99.
1385
1415
  is_greater_than(18)
1386
1416
  end
1387
1417
 
1388
- # why is value "19" here?
1389
1418
  message = <<-MESSAGE
1390
- Example did not properly validate that :attr looks like an integer
1391
- greater than 18.
1419
+ Expected Example to validate that :attr looks like an integer greater
1420
+ than 18, but this could not be proved.
1392
1421
  In checking that Example disallows :attr from being a number that is
1393
1422
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1394
1423
  expected the Example to be invalid and to produce the validation error
@@ -1415,8 +1444,8 @@ greater than 18.
1415
1444
  end
1416
1445
 
1417
1446
  message = <<-MESSAGE
1418
- Example did not properly validate that :attr looks like an integer
1419
- greater than 18.
1447
+ Expected Example to validate that :attr looks like an integer greater
1448
+ than 18, but this could not be proved.
1420
1449
  In checking that Example disallows :attr from being a number that is
1421
1450
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1422
1451
  expected the Example to be invalid, but it was valid instead.
@@ -1438,10 +1467,9 @@ greater than 18.
1438
1467
  is_greater_than(18)
1439
1468
  end
1440
1469
 
1441
- # why is value "20" here?
1442
1470
  message = <<-MESSAGE
1443
- Example did not properly validate that :attr looks like an even number
1444
- greater than 18.
1471
+ Expected Example to validate that :attr looks like an even number
1472
+ greater than 18, but this could not be proved.
1445
1473
  In checking that Example disallows :attr from being a number that is
1446
1474
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1447
1475
  expected the Example to be invalid and to produce the validation error
@@ -1468,8 +1496,8 @@ greater than 18.
1468
1496
  end
1469
1497
 
1470
1498
  message = <<-MESSAGE
1471
- Example did not properly validate that :attr looks like an even number
1472
- greater than 18.
1499
+ Expected Example to validate that :attr looks like an even number
1500
+ greater than 18, but this could not be proved.
1473
1501
  In checking that Example disallows :attr from being a number that is
1474
1502
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1475
1503
  expected the Example to be invalid, but it was valid instead.
@@ -1492,8 +1520,8 @@ greater than 18.
1492
1520
  end
1493
1521
 
1494
1522
  message = <<-MESSAGE
1495
- Example did not properly validate that :attr looks like an odd number
1496
- less than or equal to 99.
1523
+ Expected Example to validate that :attr looks like an odd number less
1524
+ than or equal to 99, but this could not be proved.
1497
1525
  In checking that Example disallows :attr from being a number that is
1498
1526
  not less than or equal to 99, after setting :attr to ‹"101"›, the
1499
1527
  matcher expected the Example to be invalid, but it was valid instead.
@@ -1516,8 +1544,8 @@ less than or equal to 99.
1516
1544
  end
1517
1545
 
1518
1546
  message = <<-MESSAGE
1519
- Example did not properly validate that :attr looks like an odd number
1520
- less than or equal to 99.
1547
+ Expected Example to validate that :attr looks like an odd number less
1548
+ than or equal to 99, but this could not be proved.
1521
1549
  In checking that Example disallows :attr from being a number that is
1522
1550
  not less than or equal to 99, after setting :attr to ‹"101"›, the
1523
1551
  matcher expected the Example to be invalid and to produce the
@@ -1546,10 +1574,9 @@ less than or equal to 99.
1546
1574
  is_less_than(99)
1547
1575
  end
1548
1576
 
1549
- # why is value "19" here?
1550
1577
  message = <<-MESSAGE
1551
- Example did not properly validate that :attr looks like an integer
1552
- greater than 18 and less than 99.
1578
+ Expected Example to validate that :attr looks like an integer greater
1579
+ than 18 and less than 99, but this could not be proved.
1553
1580
  In checking that Example disallows :attr from being a number that is
1554
1581
  not greater than 18, after setting :attr to ‹"18"›, the matcher
1555
1582
  expected the Example to be invalid and to produce the validation error
@@ -1578,8 +1605,8 @@ greater than 18 and less than 99.
1578
1605
  end
1579
1606
 
1580
1607
  message = <<-MESSAGE
1581
- Example did not properly validate that :attr looks like an integer
1582
- greater than 18 and less than 99.
1608
+ Expected Example to validate that :attr looks like an integer greater
1609
+ than 18 and less than 99, but this could not be proved.
1583
1610
  In checking that Example disallows :attr from being a number that is
1584
1611
  not less than 99, after setting :attr to ‹"100"›, the matcher expected
1585
1612
  the Example to be invalid and to produce the validation error "must be
@@ -1659,7 +1686,8 @@ greater than 18 and less than 99.
1659
1686
  attribute_name: :attr,
1660
1687
  changing_values_with: :numeric_value,
1661
1688
  expected_message: <<-MESSAGE.strip
1662
- Example did not properly validate that :attr looks like a number.
1689
+ Expected Example to validate that :attr looks like a number, but this
1690
+ could not be proved.
1663
1691
  After setting :attr to ‹"abcd"› -- which was read back as ‹"1"› -- the
1664
1692
  matcher expected the Example to be invalid, but it was valid instead.
1665
1693
 
@@ -21,7 +21,8 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher, type: :model
21
21
  attribute_name: :attr,
22
22
  changing_values_with: :never_falsy,
23
23
  expected_message: <<-MESSAGE
24
- Example did not properly validate that :attr cannot be empty/falsy.
24
+ Expected Example to validate that :attr cannot be empty/falsy, but this
25
+ could not be proved.
25
26
  After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
26
27
  -- the matcher expected the Example to be invalid, but it was valid
27
28
  instead.
@@ -35,6 +36,23 @@ Example did not properly validate that :attr cannot be empty/falsy.
35
36
  }
36
37
  }
37
38
  )
39
+
40
+ it 'fails when used in the negative' do
41
+ assertion = lambda do
42
+ expect(validating_presence).not_to matcher
43
+ end
44
+
45
+ message = <<-MESSAGE
46
+ Expected Example not to validate that :attr cannot be empty/falsy, but
47
+ this could not be proved.
48
+ After setting :attr to ‹nil›, the matcher expected the Example to be
49
+ valid, but it was invalid instead, producing these validation errors:
50
+
51
+ * attr: ["can't be blank"]
52
+ MESSAGE
53
+
54
+ expect(&assertion).to fail_with_message(message)
55
+ end
38
56
  end
39
57
 
40
58
  context 'a model without a presence validation' do
@@ -46,7 +64,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
46
64
  end
47
65
 
48
66
  message = <<-MESSAGE
49
- Example did not properly validate that :attr cannot be empty/falsy.
67
+ Expected Example to validate that :attr cannot be empty/falsy, but this
68
+ could not be proved.
50
69
  After setting :attr to ‹nil›, the matcher expected the Example to be
51
70
  invalid, but it was valid instead.
52
71
  MESSAGE
@@ -75,7 +94,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
75
94
  attribute_name: :attr,
76
95
  changing_values_with: :never_falsy,
77
96
  expected_message: <<-MESSAGE
78
- Example did not properly validate that :attr cannot be empty/falsy.
97
+ Expected Example to validate that :attr cannot be empty/falsy, but this
98
+ could not be proved.
79
99
  After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
80
100
  -- the matcher expected the Example to be invalid, but it was valid
81
101
  instead.
@@ -102,7 +122,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
102
122
  end
103
123
 
104
124
  message = <<-MESSAGE
105
- Example did not properly validate that :attr cannot be empty/falsy.
125
+ Expected Example to validate that :attr cannot be empty/falsy, but this
126
+ could not be proved.
106
127
  After setting :attr to ‹nil›, the matcher expected the Example to be
107
128
  invalid, but it was valid instead.
108
129
  MESSAGE
@@ -127,7 +148,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
127
148
  attribute_name: :attr,
128
149
  changing_values_with: :never_falsy,
129
150
  expected_message: <<-MESSAGE
130
- Example did not properly validate that :attr cannot be empty/falsy.
151
+ Expected Example to validate that :attr cannot be empty/falsy, but this
152
+ could not be proved.
131
153
  After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
132
154
  -- the matcher expected the Example to be invalid, but it was valid
133
155
  instead.
@@ -185,7 +207,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
185
207
  attribute_name: :attr,
186
208
  changing_values_with: :never_falsy,
187
209
  expected_message: <<-MESSAGE
188
- Example did not properly validate that :attr cannot be empty/falsy.
210
+ Expected Example to validate that :attr cannot be empty/falsy, but this
211
+ could not be proved.
189
212
  After setting :attr to ‹nil› -- which was read back as ‹"dummy value"›
190
213
  -- the matcher expected the Example to be invalid, but it was valid
191
214
  instead.
@@ -223,7 +246,8 @@ Example did not properly validate that :attr cannot be empty/falsy.
223
246
  end
224
247
 
225
248
  message = <<-MESSAGE
226
- Parent did not properly validate that :children cannot be empty/falsy.
249
+ Expected Parent to validate that :children cannot be empty/falsy, but
250
+ this could not be proved.
227
251
  After setting :children to ‹[]›, the matcher expected the Parent to be
228
252
  invalid, but it was valid instead.
229
253
  MESSAGE
@@ -260,8 +284,8 @@ Parent did not properly validate that :children cannot be empty/falsy.
260
284
  end
261
285
 
262
286
  message = <<-MESSAGE
263
- Example did not properly validate that :attr cannot be empty/falsy,
264
- raising a validation exception on failure.
287
+ Expected Example to validate that :attr cannot be empty/falsy, raising a
288
+ validation exception on failure, but this could not be proved.
265
289
  After setting :attr to ‹nil›, the matcher expected the Example to be
266
290
  invalid and to raise a validation exception, but the record produced
267
291
  validation errors instead.
@@ -291,12 +315,14 @@ raising a validation exception on failure.
291
315
  end
292
316
  end
293
317
 
294
- context 'an active_resource model' do
295
- context 'with the validation context' do
296
- it 'does not raise an exception' do
297
- expect {
298
- expect(active_resource_model).to validate_presence_of(:attr)
299
- }.to_not raise_exception
318
+ if rails_lte_4?
319
+ context 'an active_resource model' do
320
+ context 'with the validation context' do
321
+ it 'does not raise an exception' do
322
+ expect do
323
+ expect(active_resource_model).to validate_presence_of(:attr)
324
+ end.to_not raise_exception
325
+ end
300
326
  end
301
327
  end
302
328
  end