shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3638e6c8356a1c93b6e33b3b0dfcab34c5a5d3646567e3c91f553c490f93d52
4
- data.tar.gz: 10afc07f98e5609023024ad215cd14bdbd51a25a9c628a8ee9375c6d644e6d32
3
+ metadata.gz: 6e90bda8ad7aa6bef803eddafa1a0aee31f4228372a5d4ba30255682cc841ed6
4
+ data.tar.gz: 33c33b0e10964e0dfd3d80e9e680b361a96f817205cd513786779593e3681ae7
5
5
  SHA512:
6
- metadata.gz: ad1528def76b90a6dfdabc272b32a62393717a4e2ce386fb7b859a2a0a43bb5d92521a446ba9da26fe7a8a5e7451869e9f9840f57cde202e78ef67493823d7d2
7
- data.tar.gz: 5ee29e5681bf5e788ee9ba85d1e7f29eb77fe538b92f82b8477f42cc317c6d2d3db3072a73a531f02f18f6710bb189478d0bc855f7cfbbb56bafe293a4d43cce
6
+ metadata.gz: 71099155dc17393673681f6255d4dc52735182de139ccf798939b2a3f8ea310e5547286f91ddbd914b98d58fccb7cecc2a0277ecdab1febd6ecf7b918de888b0
7
+ data.tar.gz: 1b4624af4740f43192336f624f748c3506131d1ce57f29c65591dce5f0ceee8e0d12a5860a81ddadadec4e423e94662f166a5d91dc7df82050d53353e82994a7
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2018, Tammer Saleh and thoughtbot, inc.
1
+ Copyright (c) 2006-2019, Tammer Saleh and thoughtbot, inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  [![shoulda-matchers][logo]][website]
4
4
 
5
5
  Shoulda Matchers provides RSpec- and Minitest-compatible one-liners that test
6
- common Rails functionality. These tests would otherwise be much longer, more
7
- complex, and error-prone.
6
+ common Rails functionality. These tests, if written by hand, would be much
7
+ longer, more complex, and error-prone.
8
+
9
+ **[View the documentation for the latest version (4.0.0).][rubydocs]**
10
+
11
+ ---
8
12
 
9
- * [Documentation](#documentation)
10
- * [Compatibility](#compatibility)
11
13
  * [Getting started](#getting-started)
12
14
  * [RSpec](#rspec)
13
15
  * [Availability of matchers in various example groups](#availability-of-matchers-in-various-example-groups)
@@ -18,23 +20,12 @@ complex, and error-prone.
18
20
  * [ActiveRecord matchers](#activerecord-matchers)
19
21
  * [ActionController matchers](#actioncontroller-matchers)
20
22
  * [Independent matchers](#independent-matchers)
23
+ * [Compatibility](#compatibility)
21
24
  * [Contributing](#contributing)
22
25
  * [Versioning](#versioning)
23
26
  * [License](#license)
24
27
  * [About thoughtbot](#about-thoughtbot)
25
28
 
26
- ## Documentation
27
-
28
- [View the official documentation for the latest version (4.0.0.rc1).][rubydocs]
29
-
30
- ## Compatibility
31
-
32
- Shoulda Matchers 4 is tested and supported against Rails 5.x, Rails 4.2, RSpec
33
- 3.x, Minitest 5, Minitest 4, and Ruby 2.2+.
34
-
35
- For Rails 4.0/4.1 and Ruby 2.0/2.1 compatibility, please use shoulda-matchers
36
- [3.1.2](https://github.com/thoughtbot/shoulda-matchers/releases/tag/v3.1.2).
37
-
38
29
  ## Getting started
39
30
 
40
31
  ### RSpec
@@ -43,8 +34,8 @@ Start by including `shoulda-matchers` in your Gemfile:
43
34
 
44
35
  ```ruby
45
36
  group :test do
46
- gem 'shoulda-matchers', '4.0.0.rc1'
47
- gem 'rails-controller-testing' # If you are using Rails 5.x
37
+ gem 'shoulda-matchers'
38
+ gem 'rails-controller-testing'
48
39
  end
49
40
  ```
50
41
 
@@ -53,30 +44,52 @@ Now you need to tell the gem a couple of things:
53
44
  * Which test framework you're using
54
45
  * Which portion of the matchers you want to use
55
46
 
56
- You can supply this information by using a configuration block. Place the
57
- following in `rails_helper.rb`:
47
+ You can supply this information by providing a configuration block. Where this
48
+ goes and what this contains depends on your project.
49
+
50
+ #### Rails apps
51
+
52
+ Assuming you are testing a Rails app, simply place this at the bottom of
53
+ `spec/rails_helper.rb` (or in a support file if you so choose):
58
54
 
59
55
  ```ruby
60
56
  Shoulda::Matchers.configure do |config|
61
57
  config.integrate do |with|
62
- # Choose a test framework:
63
58
  with.test_framework :rspec
64
- with.test_framework :minitest
65
- with.test_framework :minitest_4
66
- with.test_framework :test_unit
59
+ with.library :rails
60
+ end
61
+ end
62
+ ```
63
+
64
+ Now you're ready to use matchers in your tests! For instance, you might decide
65
+ to add a matcher to one of your models:
67
66
 
68
- # Choose one or more libraries:
67
+ ```ruby
68
+ RSpec.describe Person, type: :model do
69
+ it { should validate_presence_of(:name) }
70
+ end
71
+ ```
72
+
73
+ #### Non-Rails apps
74
+
75
+ If your project isn't a Rails app, but you still make use of ActiveRecord or
76
+ ActiveModel, you can still use this gem too! In that case, you'll want to place
77
+ the following configuration at the bottom of `spec/spec_helper.rb`:
78
+
79
+ ```ruby
80
+ Shoulda::Matchers.configure do |config|
81
+ config.integrate do |with|
82
+ with.test_framework :rspec
83
+
84
+ # Keep as many of these lines as are necessary:
69
85
  with.library :active_record
70
86
  with.library :active_model
71
- with.library :action_controller
72
- # Or, choose all of the above:
73
- with.library :rails
74
87
  end
75
88
  end
76
89
  ```
77
90
 
78
- Now you can use matchers in your tests. For instance, a model test might look
79
- like this:
91
+ Now you're ready to use matchers in your tests! For instance, you might decide
92
+ to add a matcher to one of your models:
80
93
 
81
94
  ```ruby
82
95
  RSpec.describe Person, type: :model do
@@ -84,10 +97,14 @@ RSpec.describe Person, type: :model do
84
97
  end
85
98
  ```
86
99
 
100
+ For more of an idea of what you can use, [see the list of matchers
101
+ below](#matchers).
102
+
87
103
  #### Availability of matchers in various example groups
88
104
 
89
- Since shoulda-matchers provides four categories of matchers, there are four
90
- different levels where you can use these matchers:
105
+ Regardless of your project, it's important to keep in mind that since
106
+ shoulda-matchers provides four categories of matchers, there are four different
107
+ levels where you can use these matchers:
91
108
 
92
109
  * ActiveRecord and ActiveModel matchers are available only in model example
93
110
  groups, i.e., those tagged with `type: :model` or in files located under
@@ -99,11 +116,13 @@ different levels where you can use these matchers:
99
116
  tagged with `type: :routing` or in files located under `spec/routing`.
100
117
  * Independent matchers are available in all example groups.
101
118
 
102
- **If you are using ActiveModel or ActiveRecord outside of Rails** and you want
119
+ **⚠️ If you are using ActiveModel or ActiveRecord outside of Rails** and you want
103
120
  to use model matchers in certain example groups, you'll need to manually include
104
121
  them. Here's a good way of doing that:
105
122
 
106
123
  ```ruby
124
+ require 'shoulda-matchers'
125
+
107
126
  RSpec.configure do |config|
108
127
  config.include(Shoulda::Matchers::ActiveModel, type: :model)
109
128
  config.include(Shoulda::Matchers::ActiveRecord, type: :model)
@@ -122,8 +141,8 @@ end
122
141
 
123
142
  Note that in this README and throughout the documentation we're using the
124
143
  `should` form of RSpec's one-liner syntax over `is_expected.to`. The `should`
125
- form works regardless of how you've configured RSpec -- meaning you can still
126
- use it even when using the `expect` syntax. But if you prefer to use
144
+ form works regardless of how you've configured RSpec meaning you can still use
145
+ it even when using the `expect` syntax. But if you prefer to use
127
146
  `is_expected.to`, you can do that too:
128
147
 
129
148
  ```ruby
@@ -138,8 +157,8 @@ Shoulda Matchers was originally a component of [Shoulda][shoulda], a gem that
138
157
  also provides `should` and `context` syntax via
139
158
  [`shoulda-context`][shoulda-context].
140
159
 
141
- At the moment, `shoulda` has not been updated to support `shoulda-matchers` 3.x and 4.x,
142
- so you'll want to add the following to your Gemfile:
160
+ At the moment, `shoulda` has not been updated to support `shoulda-matchers` 3.x
161
+ and 4.x, so you'll want to add the following to your Gemfile:
143
162
 
144
163
  ```ruby
145
164
  group :test do
@@ -148,8 +167,8 @@ group :test do
148
167
  end
149
168
  ```
150
169
 
151
- Now you can use matchers in your tests. For instance a model test might look
152
- like this:
170
+ Now you're ready to use matchers in your tests! For instance, you might decide
171
+ to add a matcher to one of your models:
153
172
 
154
173
  ```ruby
155
174
  class PersonTest < ActiveSupport::TestCase
@@ -157,6 +176,9 @@ class PersonTest < ActiveSupport::TestCase
157
176
  end
158
177
  ```
159
178
 
179
+ For more of an idea of what you can use, [see the list of matchers
180
+ below](#matchers).
181
+
160
182
  ## Matchers
161
183
 
162
184
  ### ActiveModel matchers
@@ -243,6 +265,16 @@ end
243
265
  tests that an object forwards messages to other, internal objects by way of
244
266
  delegation.
245
267
 
268
+ ## Compatibility
269
+
270
+ Shoulda Matchers 4 is tested and supported against Rails 5.x, Rails 4.2, RSpec
271
+ 3.x, Minitest 5, Minitest 4, and Ruby 2.3+.
272
+
273
+ For Rails 4.0/4.1 and Ruby 2.0/2.1/2.2 compatibility, please use
274
+ [shoulda-matchers 3.1.3][v3.1.3].
275
+
276
+ [v3.1.3]: https://github.com/thoughtbot/shoulda-matchers/releases/tag/v3.1.3
277
+
246
278
  ## Contributing
247
279
 
248
280
  Shoulda Matchers is open source, and we are grateful for
@@ -259,7 +291,7 @@ Shoulda Matchers follows Semantic Versioning 2.0 as defined at
259
291
 
260
292
  ## License
261
293
 
262
- Shoulda Matchers is copyright © 2006-2018
294
+ Shoulda Matchers is copyright © 2006-2019
263
295
  [thoughtbot, inc][thoughtbot-website]. It is free software,
264
296
  and may be redistributed under the terms specified in the
265
297
  [MIT-LICENSE](MIT-LICENSE) file.
@@ -16,6 +16,8 @@ require 'shoulda/matchers/action_controller/session_store'
16
16
 
17
17
  module Shoulda
18
18
  module Matchers
19
+ # This module provides matchers that are used to test behavior within
20
+ # controllers.
19
21
  module ActionController
20
22
  end
21
23
  end
@@ -32,9 +32,8 @@ require 'shoulda/matchers/active_model/have_secure_password_matcher'
32
32
 
33
33
  module Shoulda
34
34
  module Matchers
35
- # This mixin provides matchers that are used to test behavior, such as
36
- # validations, that you've added to your ActiveModel (or ActiveRecord)
37
- # objects.
35
+ # This module provides matchers that are used to test behavior within
36
+ # ActiveModel or ActiveRecord classes.
38
37
  #
39
38
  # ### Testing conditional validations
40
39
  #
@@ -322,6 +322,7 @@ EOT
322
322
 
323
323
  def allow_nil
324
324
  @options[:allow_nil] = true
325
+ self
325
326
  end
326
327
 
327
328
  def expects_to_allow_nil?
@@ -24,6 +24,8 @@ require "shoulda/matchers/active_record/validate_uniqueness_of_matcher"
24
24
 
25
25
  module Shoulda
26
26
  module Matchers
27
+ # This module provides matchers that are used to test behavior within
28
+ # ActiveRecord classes.
27
29
  module ActiveRecord
28
30
  end
29
31
  end
@@ -272,6 +272,35 @@ module Shoulda
272
272
  # should belong_to(:organization).required
273
273
  # end
274
274
  #
275
+ # #### without_validating_presence
276
+ #
277
+ # Use `without_validating_presence` with `belong_to` to prevent the
278
+ # matcher from checking whether the association disallows nil (Rails 5+
279
+ # only). This can be helpful if you have a custom hook that always sets
280
+ # the association to a meaningful value:
281
+ #
282
+ # class Person < ActiveRecord::Base
283
+ # belongs_to :organization
284
+ #
285
+ # before_validation :autoassign_organization
286
+ #
287
+ # private
288
+ #
289
+ # def autoassign_organization
290
+ # self.organization = Organization.create!
291
+ # end
292
+ # end
293
+ #
294
+ # # RSpec
295
+ # describe Person
296
+ # it { should belong_to(:organization).without_validating_presence }
297
+ # end
298
+ #
299
+ # # Minitest (Shoulda)
300
+ # class PersonTest < ActiveSupport::TestCase
301
+ # should belong_to(:organization).without_validating_presence
302
+ # end
303
+ #
275
304
  # ##### optional
276
305
  #
277
306
  # Use `optional` to assert that the association is allowed to be nil.
@@ -1092,6 +1121,11 @@ module Shoulda
1092
1121
  self
1093
1122
  end
1094
1123
 
1124
+ def without_validating_presence
1125
+ remove_submatcher(AssociationMatchers::RequiredMatcher)
1126
+ self
1127
+ end
1128
+
1095
1129
  def description
1096
1130
  description = "#{macro_description} #{name}"
1097
1131
  description += " class_name => #{options[:class_name]}" if options.key?(:class_name)
@@ -7,6 +7,7 @@ module Shoulda
7
7
  attr_reader :missing_option
8
8
 
9
9
  def initialize(attribute_name, optional)
10
+ @attribute_name = attribute_name
10
11
  @optional = optional
11
12
  @submatcher = ActiveModel::AllowValueMatcher.new(nil).
12
13
  for(attribute_name)
@@ -21,16 +22,38 @@ module Shoulda
21
22
  if submatcher_passes?(subject)
22
23
  true
23
24
  else
24
- @missing_option =
25
- 'the association should have been defined ' +
26
- "with `optional: #{optional}`, but was not"
25
+ @missing_option = 'and for the record '
26
+
27
+ missing_option <<
28
+ if optional
29
+ 'not to '
30
+ else
31
+ 'to '
32
+ end
33
+
34
+ missing_option << (
35
+ 'fail validation if ' +
36
+ ":#{attribute_name} is unset; i.e., either the association " +
37
+ 'should have been defined with `optional: ' +
38
+ "#{optional.inspect}`, or there "
39
+ )
40
+
41
+ missing_option <<
42
+ if optional
43
+ 'should not '
44
+ else
45
+ 'should '
46
+ end
47
+
48
+ missing_option << "be a presence validation on :#{attribute_name}"
49
+
27
50
  false
28
51
  end
29
52
  end
30
53
 
31
54
  private
32
55
 
33
- attr_reader :optional, :submatcher
56
+ attr_reader :attribute_name, :optional, :submatcher
34
57
 
35
58
  def submatcher_passes?(subject)
36
59
  if optional
@@ -7,6 +7,7 @@ module Shoulda
7
7
  attr_reader :missing_option
8
8
 
9
9
  def initialize(attribute_name, required)
10
+ @attribute_name = attribute_name
10
11
  @required = required
11
12
  @submatcher = ActiveModel::DisallowValueMatcher.new(nil).
12
13
  for(attribute_name).
@@ -22,16 +23,38 @@ module Shoulda
22
23
  if submatcher_passes?(subject)
23
24
  true
24
25
  else
25
- @missing_option =
26
- 'the association should have been defined ' +
27
- "with `required: #{required}`, but was not"
26
+ @missing_option = 'and for the record '
27
+
28
+ missing_option <<
29
+ if required
30
+ 'to '
31
+ else
32
+ 'not to '
33
+ end
34
+
35
+ missing_option << (
36
+ 'fail validation if ' +
37
+ ":#{attribute_name} is unset; i.e., either the association " +
38
+ 'should have been defined with `required: ' +
39
+ "#{required.inspect}`, or there "
40
+ )
41
+
42
+ missing_option <<
43
+ if required
44
+ 'should '
45
+ else
46
+ 'should not '
47
+ end
48
+
49
+ missing_option << "be a presence validation on :#{attribute_name}"
50
+
28
51
  false
29
52
  end
30
53
  end
31
54
 
32
55
  private
33
56
 
34
- attr_reader :required, :submatcher
57
+ attr_reader :attribute_name, :required, :submatcher
35
58
 
36
59
  def submatcher_passes?(subject)
37
60
  if required
@@ -144,7 +144,7 @@ module Shoulda
144
144
  # unique, but the scoped attributes are not unique either.
145
145
  #
146
146
  # class Post < ActiveRecord::Base
147
- # validates :slug, uniqueness: true, scope: :journal_id
147
+ # validates :slug, uniqueness: { scope: :journal_id }
148
148
  # end
149
149
  #
150
150
  # # RSpec
@@ -4,7 +4,8 @@ require 'shoulda/matchers/independent/delegate_method_matcher/target_not_defined
4
4
 
5
5
  module Shoulda
6
6
  module Matchers
7
- # Matchers for non-Rails-dependent code.
7
+ # This module provides matchers that are used to test behavior outside of
8
+ # Rails-specific classes.
8
9
  module Independent
9
10
  end
10
11
  end
@@ -128,20 +128,16 @@ module Shoulda
128
128
  options
129
129
  )
130
130
  default_translation_keys = [
131
+ :"activemodel.errors.models.#{model_name}.attributes.#{attribute}.#{type}",
132
+ :"activemodel.errors.models.#{model_name}.#{type}",
133
+ :"activemodel.errors.messages.#{type}",
134
+ :"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{type}",
131
135
  :"activerecord.errors.models.#{model_name}.#{type}",
132
136
  :"activerecord.errors.messages.#{type}",
133
137
  :"errors.attributes.#{attribute}.#{type}",
134
138
  :"errors.messages.#{type}",
135
139
  ]
136
- primary_translation_key = [
137
- :activerecord,
138
- :errors,
139
- :models,
140
- model_name,
141
- :attributes,
142
- attribute,
143
- type,
144
- ]
140
+ primary_translation_key = default_translation_keys.shift
145
141
  translate_options =
146
142
  { default: default_translation_keys }.merge(options)
147
143
  I18n.translate(primary_translation_key, translate_options)