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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +72 -40
- data/lib/shoulda/matchers/action_controller.rb +2 -0
- data/lib/shoulda/matchers/active_model.rb +2 -3
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +2 -1
- data/lib/shoulda/matchers/rails_shim.rb +5 -9
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +1 -0
- data/shoulda-matchers.gemspec +11 -3
- metadata +13 -340
- data/.gitignore +0 -12
- data/.hound.yml +0 -3
- data/.hound/ruby.yml +0 -1062
- data/.python-version +0 -1
- data/.rubocop.yml +0 -15
- data/.travis.yml +0 -21
- data/.yardopts +0 -10
- data/Appraisals +0 -105
- data/CONTRIBUTING.md +0 -172
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -59
- data/MAINTAINING.md +0 -250
- data/NEWS.md +0 -1235
- data/Rakefile +0 -46
- data/bin/setup +0 -190
- data/custom_plan.rb +0 -104
- data/doc_config/gh-pages/index.html.erb +0 -9
- data/doc_config/yard/setup.rb +0 -22
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
- data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
- data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
- data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
- data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
- data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
- data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
- data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
- data/gemfiles/4.2.gemfile +0 -39
- data/gemfiles/4.2.gemfile.lock +0 -246
- data/gemfiles/5.0.gemfile +0 -37
- data/gemfiles/5.0.gemfile.lock +0 -238
- data/gemfiles/5.1.gemfile +0 -38
- data/gemfiles/5.1.gemfile.lock +0 -254
- data/gemfiles/5.2.gemfile +0 -40
- data/gemfiles/5.2.gemfile.lock +0 -273
- data/script/install_gems_in_all_appraisals +0 -16
- data/script/run_all_tests +0 -16
- data/script/supported_ruby_versions +0 -7
- data/script/update_gem_in_all_appraisals +0 -17
- data/script/update_gems_in_all_appraisals +0 -16
- data/spec/acceptance/active_model_integration_spec.rb +0 -23
- data/spec/acceptance/independent_matchers_spec.rb +0 -125
- data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
- data/spec/acceptance/rails_integration_spec.rb +0 -156
- data/spec/acceptance_spec_helper.rb +0 -23
- data/spec/doublespeak_spec_helper.rb +0 -2
- data/spec/report_warnings.rb +0 -7
- data/spec/spec_helper.rb +0 -20
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
- data/spec/support/acceptance/helpers.rb +0 -33
- data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
- data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
- data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
- data/spec/support/acceptance/matchers/have_output.rb +0 -31
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
- data/spec/support/tests/bundle.rb +0 -94
- data/spec/support/tests/command_runner.rb +0 -230
- data/spec/support/tests/current_bundle.rb +0 -55
- data/spec/support/tests/database.rb +0 -28
- data/spec/support/tests/database_adapters/postgresql.rb +0 -25
- data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
- data/spec/support/tests/database_configuration.rb +0 -33
- data/spec/support/tests/database_configuration_registry.rb +0 -28
- data/spec/support/tests/filesystem.rb +0 -100
- data/spec/support/tests/version.rb +0 -45
- data/spec/support/unit/active_record/create_table.rb +0 -54
- data/spec/support/unit/attribute.rb +0 -45
- data/spec/support/unit/capture.rb +0 -46
- data/spec/support/unit/change_value.rb +0 -111
- data/spec/support/unit/create_model_arguments/basic.rb +0 -135
- data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
- data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
- data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
- data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
- data/spec/support/unit/helpers/active_model_versions.rb +0 -32
- data/spec/support/unit/helpers/active_record_versions.rb +0 -44
- data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
- data/spec/support/unit/helpers/class_builder.rb +0 -90
- data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
- data/spec/support/unit/helpers/controller_builder.rb +0 -63
- data/spec/support/unit/helpers/database_helpers.rb +0 -20
- data/spec/support/unit/helpers/i18n_faker.rb +0 -15
- data/spec/support/unit/helpers/mailer_builder.rb +0 -12
- data/spec/support/unit/helpers/message_helpers.rb +0 -19
- data/spec/support/unit/helpers/model_builder.rb +0 -114
- data/spec/support/unit/helpers/rails_versions.rb +0 -42
- data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
- data/spec/support/unit/i18n.rb +0 -7
- data/spec/support/unit/load_environment.rb +0 -12
- data/spec/support/unit/matchers/deprecate.rb +0 -60
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
- data/spec/support/unit/matchers/print_warning_including.rb +0 -67
- data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
- data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
- data/spec/support/unit/model_creators.rb +0 -19
- data/spec/support/unit/model_creators/active_model.rb +0 -39
- data/spec/support/unit/model_creators/active_record.rb +0 -42
- data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
- data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
- data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
- data/spec/support/unit/model_creators/basic.rb +0 -102
- data/spec/support/unit/rails_application.rb +0 -151
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
- data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
- data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
- data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
- data/spec/support/unit/validation_matcher_scenario.rb +0 -60
- data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
- data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
- data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
- data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
- data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
- data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
- data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
- data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
- data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
- data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
- data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
- data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
- data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
- data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
- data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
- data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
- data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
- data/spec/unit_spec_helper.rb +0 -54
- data/spec/warnings_spy.rb +0 -64
- data/spec/warnings_spy/filesystem.rb +0 -45
- data/spec/warnings_spy/partitioner.rb +0 -36
- data/spec/warnings_spy/reader.rb +0 -53
- data/spec/warnings_spy/reporter.rb +0 -88
- data/tasks/documentation.rb +0 -199
- data/zeus.json +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e90bda8ad7aa6bef803eddafa1a0aee31f4228372a5d4ba30255682cc841ed6
|
4
|
+
data.tar.gz: 33c33b0e10964e0dfd3d80e9e680b361a96f817205cd513786779593e3681ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71099155dc17393673681f6255d4dc52735182de139ccf798939b2a3f8ea310e5547286f91ddbd914b98d58fccb7cecc2a0277ecdab1febd6ecf7b918de888b0
|
7
|
+
data.tar.gz: 1b4624af4740f43192336f624f748c3506131d1ce57f29c65591dce5f0ceee8e0d12a5860a81ddadadec4e423e94662f166a5d91dc7df82050d53353e82994a7
|
data/MIT-LICENSE
CHANGED
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
|
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'
|
47
|
-
gem 'rails-controller-testing'
|
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
|
57
|
-
|
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.
|
65
|
-
|
66
|
-
|
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
|
-
|
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
|
79
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
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
|
126
|
-
|
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
|
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
|
152
|
-
|
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-
|
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.
|
@@ -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
|
36
|
-
#
|
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
|
#
|
@@ -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
|
-
|
26
|
-
|
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
|
-
|
27
|
-
|
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:
|
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
|
-
#
|
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)
|