shoulda-matchers 4.3.0 → 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +170 -90
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -89
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +29 -27
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
- data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/active_model.rb +0 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +29 -27
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
- data/lib/shoulda/matchers/active_model/helpers.rb +1 -1
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +10 -2
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +8 -7
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +28 -46
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +33 -9
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +72 -27
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +31 -6
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +4 -9
- data/lib/shoulda/matchers/active_record.rb +26 -24
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
- data/lib/shoulda/matchers/active_record/association_matcher.rb +119 -50
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +18 -9
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +39 -17
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +11 -7
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +30 -9
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
- data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +80 -73
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +0 -1
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -13
- data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +7 -40
- data/lib/shoulda/matchers/util.rb +16 -4
- data/lib/shoulda/matchers/util/word_wrap.rb +8 -8
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +3 -3
- data/shoulda-matchers.gemspec +12 -9
- metadata +15 -15
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
- data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4bebbe2dbe599d4b1c19061803f12abb87578322e17a96a56d0442399ef72a9
|
4
|
+
data.tar.gz: 4742002f75d6cc61f6eb4419a4729632c000519ff1bd1e9c52754c251835294d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b7c3f78337afc8da72887fa743956839d637e6eb277b0c6ba06a55837468b4ec598ae1bf534b58c9287b5b3e381e7ffe228a19b32a78c434f1048ffa6378441
|
7
|
+
data.tar.gz: 5944d64e1ab63143363ad0a2ee1f32fe761178664fe2e1bff38b71b324341719ec48619cc687d1b185dc1544e32badc65a21f16c694b33147db100fd93a33d2e
|
data/{MIT-LICENSE → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
# Shoulda Matchers [![Gem Version][version-badge]][rubygems] [![Build Status][
|
1
|
+
# Shoulda Matchers [![Gem Version][version-badge]][rubygems] [![Build Status][github-actions-badge]][github-actions] [![Total Downloads][downloads-total]][rubygems] [![Downloads][downloads-badge]][rubygems]
|
2
2
|
|
3
3
|
[version-badge]: https://img.shields.io/gem/v/shoulda-matchers.svg
|
4
4
|
[rubygems]: https://rubygems.org/gems/shoulda-matchers
|
5
|
-
[
|
6
|
-
[
|
5
|
+
[github-actions-badge]: https://img.shields.io/github/workflow/status/thoughtbot/shoulda-matchers/Test
|
6
|
+
[github-actions]: https://github.com/thoughtbot/shoulda-matchers/actions
|
7
7
|
[downloads-total]: https://img.shields.io/gem/dt/shoulda-matchers.svg
|
8
8
|
[downloads-badge]: https://img.shields.io/gem/dtv/shoulda-matchers.svg
|
9
9
|
[downloads-badge]: https://img.shields.io/gem/dtv/shoulda-matchers.svg
|
10
|
-
[hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
11
|
-
[hound]: https://houndci.com
|
12
10
|
|
13
11
|
[![shoulda-matchers][logo]][website]
|
14
12
|
|
@@ -22,10 +20,10 @@ complex, and error-prone.
|
|
22
20
|
## Quick links
|
23
21
|
|
24
22
|
📖 **[Read the documentation for the latest version][rubydocs].**
|
25
|
-
📢 **[See what's changed in
|
23
|
+
📢 **[See what's changed in recent versions][changelog].**
|
26
24
|
|
27
|
-
[rubydocs]:
|
28
|
-
[
|
25
|
+
[rubydocs]: https://matchers.shoulda.io/docs
|
26
|
+
[changelog]: CHANGELOG.md
|
29
27
|
|
30
28
|
## Table of contents
|
31
29
|
|
@@ -41,10 +39,12 @@ complex, and error-prone.
|
|
41
39
|
* [ActiveRecord matchers](#activerecord-matchers)
|
42
40
|
* [ActionController matchers](#actioncontroller-matchers)
|
43
41
|
* [Independent matchers](#independent-matchers)
|
44
|
-
* [
|
42
|
+
* [Extensions](#extensions)
|
45
43
|
* [Contributing](#contributing)
|
44
|
+
* [Compatibility](#compatibility)
|
46
45
|
* [Versioning](#versioning)
|
47
|
-
* [
|
46
|
+
* [Team](#team)
|
47
|
+
* [Copyright/License](#copyright-license)
|
48
48
|
* [About thoughtbot](#about-thoughtbot)
|
49
49
|
|
50
50
|
## Getting started
|
@@ -55,21 +55,21 @@ Start by including `shoulda-matchers` in your Gemfile:
|
|
55
55
|
|
56
56
|
```ruby
|
57
57
|
group :test do
|
58
|
-
gem 'shoulda-matchers'
|
58
|
+
gem 'shoulda-matchers', '~> 4.0'
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
-
|
62
|
+
Then run `bundle install`.
|
63
63
|
|
64
|
-
|
65
|
-
* Which portion of the matchers you want to use
|
64
|
+
Now you need to configure the gem by telling it:
|
66
65
|
|
67
|
-
|
68
|
-
|
66
|
+
* which matchers you want to use in your tests
|
67
|
+
* that you're using RSpec so that it can make those matchers available in
|
68
|
+
your example groups
|
69
69
|
|
70
70
|
#### Rails apps
|
71
71
|
|
72
|
-
|
72
|
+
If you're working on a Rails app, simply place this at the bottom of
|
73
73
|
`spec/rails_helper.rb` (or in a support file if you so choose):
|
74
74
|
|
75
75
|
```ruby
|
@@ -81,13 +81,12 @@ Shoulda::Matchers.configure do |config|
|
|
81
81
|
end
|
82
82
|
```
|
83
83
|
|
84
|
-
Now you're ready to [use matchers in your tests](#usage)!
|
85
|
-
|
86
84
|
#### Non-Rails apps
|
87
85
|
|
88
|
-
If
|
89
|
-
ActiveModel, you can still use this gem too! In that case,
|
90
|
-
the following configuration at the bottom of
|
86
|
+
If you're not working on a Rails app, but you still make use of ActiveRecord or
|
87
|
+
ActiveModel in your project, you can still use this gem too! In that case,
|
88
|
+
you'll want to place the following configuration at the bottom of
|
89
|
+
`spec/spec_helper.rb`:
|
91
90
|
|
92
91
|
```ruby
|
93
92
|
Shoulda::Matchers.configure do |config|
|
@@ -101,45 +100,83 @@ Shoulda::Matchers.configure do |config|
|
|
101
100
|
end
|
102
101
|
```
|
103
102
|
|
104
|
-
Now you're ready to [use matchers in your tests](#usage)!
|
105
|
-
|
106
103
|
### Minitest
|
107
104
|
|
108
|
-
|
109
|
-
|
110
|
-
[`shoulda-context`][shoulda-context].
|
105
|
+
If you're using our umbrella gem [Shoulda], then make sure that you're using the
|
106
|
+
latest version:
|
111
107
|
|
112
|
-
|
113
|
-
|
108
|
+
```ruby
|
109
|
+
group :test do
|
110
|
+
gem 'shoulda', '~> 4.0'
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
[Shoulda]: https://github.com/thoughtbot/shoulda
|
114
115
|
|
115
|
-
|
116
|
-
and 4.x, so you'll want to add the following to your Gemfile:
|
116
|
+
Otherwise, add `shoulda-matchers` to your Gemfile:
|
117
117
|
|
118
118
|
```ruby
|
119
119
|
group :test do
|
120
|
-
gem 'shoulda', '~>
|
121
|
-
|
122
|
-
|
120
|
+
gem 'shoulda-matchers', '~> 4.0'
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
Then run `bundle install`.
|
125
|
+
|
126
|
+
Now you need to configure the gem by telling it:
|
127
|
+
|
128
|
+
* which matchers you want to use in your tests
|
129
|
+
* that you're using Minitest so that it can make those matchers available in
|
130
|
+
your test case classes
|
131
|
+
|
132
|
+
#### Rails apps
|
133
|
+
|
134
|
+
If you're working on a Rails app, simply place this at the bottom of
|
135
|
+
`test/test_helper.rb`:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
Shoulda::Matchers.configure do |config|
|
139
|
+
config.integrate do |with|
|
140
|
+
with.test_framework :minitest
|
141
|
+
with.library :rails
|
142
|
+
end
|
123
143
|
end
|
124
144
|
```
|
125
145
|
|
126
|
-
|
146
|
+
#### Non-Rails apps
|
147
|
+
|
148
|
+
If you're not working on a Rails app, but you still make use of ActiveRecord or
|
149
|
+
ActiveModel in your project, you can still use this gem too! In that case,
|
150
|
+
you'll want to place the following configuration at the bottom of
|
151
|
+
`test/test_helper.rb`:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
Shoulda::Matchers.configure do |config|
|
155
|
+
config.integrate do |with|
|
156
|
+
with.test_framework :minitest
|
157
|
+
|
158
|
+
# Keep as many of these lines as are necessary:
|
159
|
+
with.library :active_record
|
160
|
+
with.library :active_model
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
127
164
|
|
128
165
|
## Usage
|
129
166
|
|
130
|
-
|
131
|
-
|
167
|
+
Most of the matchers provided by this gem are useful in a Rails context, and as
|
168
|
+
such, can be used for different parts of a Rails app:
|
132
169
|
|
133
170
|
* [database models backed by ActiveRecord](#activemodel-matchers)
|
134
171
|
* [non-database models, form objects, etc. backed by
|
135
172
|
ActiveModel](#activerecord-matchers)
|
136
173
|
* [controllers](#actioncontroller-matchers)
|
137
174
|
* [routes](#routing-matchers) (RSpec only)
|
138
|
-
* [
|
175
|
+
* [Rails-specific features like `delegate`](#independent-matchers)
|
139
176
|
|
140
|
-
|
141
|
-
|
142
|
-
test case may look something like:
|
177
|
+
As the name of the gem indicates, most matchers are designed to be used in
|
178
|
+
"one-liner" form using the `should` macro, a special directive available in both
|
179
|
+
RSpec and [Shoulda]. For instance, a model test case may look something like:
|
143
180
|
|
144
181
|
``` ruby
|
145
182
|
# RSpec
|
@@ -167,16 +204,17 @@ class MenuItemTest < ActiveSupport::TestCase
|
|
167
204
|
end
|
168
205
|
```
|
169
206
|
|
170
|
-
|
207
|
+
[See below](#matchers) for the full set of matchers that you can use.
|
171
208
|
|
172
209
|
### On the subject of `subject`
|
173
210
|
|
174
211
|
For both RSpec and Shoulda, the **subject** is an implicit reference to the
|
175
|
-
object under test, and
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
212
|
+
object under test, and through the use of `should` as demonstrated above, all of
|
213
|
+
the matchers make use of `subject` internally when they are run. A `subject` is
|
214
|
+
always set automatically by your test framework in any given test case; however,
|
215
|
+
in certain cases it can be advantageous to override it. For instance, when
|
216
|
+
testing validations in a model, it is customary to provide a valid model instead
|
217
|
+
of a fresh one:
|
180
218
|
|
181
219
|
``` ruby
|
182
220
|
# RSpec
|
@@ -234,11 +272,19 @@ end
|
|
234
272
|
|
235
273
|
### Availability of RSpec matchers in example groups
|
236
274
|
|
275
|
+
#### Rails projects
|
276
|
+
|
237
277
|
If you're using RSpec, then you're probably familiar with the concept of example
|
238
|
-
groups
|
239
|
-
|
240
|
-
|
241
|
-
groups
|
278
|
+
groups. Example groups can be assigned tags order to assign different behavior
|
279
|
+
to different kinds of example groups. This comes into play especially when using
|
280
|
+
`rspec-rails`, where, for instance, controller example groups, tagged with
|
281
|
+
`type: :controller`, are written differently than request example groups, tagged
|
282
|
+
with `type: :request`. This difference in writing style arises because
|
283
|
+
`rspec-rails` mixes different behavior and methods into controller example
|
284
|
+
groups vs. request example groups.
|
285
|
+
|
286
|
+
Relying on this behavior, Shoulda Matchers automatically makes certain matchers
|
287
|
+
available in certain kinds of example groups:
|
242
288
|
|
243
289
|
* ActiveRecord and ActiveModel matchers are available only in model example
|
244
290
|
groups, i.e., those tagged with `type: :model` or in files located under
|
@@ -250,13 +296,27 @@ groups:
|
|
250
296
|
tagged with `type: :routing` or in files located under `spec/routing`.
|
251
297
|
* Independent matchers are available in all example groups.
|
252
298
|
|
253
|
-
As long as you're using Rails, you don't need to worry about
|
254
|
-
should "just work".
|
299
|
+
As long as you're using Rails, you don't need to worry about these details —
|
300
|
+
everything should "just work".
|
301
|
+
|
302
|
+
#### Non-Rails projects
|
255
303
|
|
256
|
-
**
|
257
|
-
you want to use model matchers in certain example
|
258
|
-
manually include the module that holds those matchers
|
259
|
-
|
304
|
+
**What if you are using ActiveModel or ActiveRecord outside of Rails, however,
|
305
|
+
and you want to use model matchers in a certain example group?** Then you'll
|
306
|
+
need to manually include the module that holds those matchers into that example
|
307
|
+
group. For instance, you might have to say:
|
308
|
+
|
309
|
+
``` ruby
|
310
|
+
RSpec.describe MySpecialModel do
|
311
|
+
include Shoulda::Matchers::ActiveModel
|
312
|
+
include Shoulda::Matchers::ActiveRecord
|
313
|
+
end
|
314
|
+
```
|
315
|
+
|
316
|
+
If you have a lot of similar example groups in which you need to do this, then
|
317
|
+
you might find it more helpful to tag your example groups appropriately, then
|
318
|
+
instruct RSpec to mix these modules into any example groups that have that tag.
|
319
|
+
For instance, you could add this to your `rails_helper.rb`:
|
260
320
|
|
261
321
|
```ruby
|
262
322
|
RSpec.configure do |config|
|
@@ -265,21 +325,20 @@ RSpec.configure do |config|
|
|
265
325
|
end
|
266
326
|
```
|
267
327
|
|
268
|
-
|
328
|
+
And from then on, you could say:
|
269
329
|
|
270
330
|
```ruby
|
271
|
-
describe MySpecialModel, type: :model do
|
331
|
+
RSpec.describe MySpecialModel, type: :model do
|
272
332
|
# ...
|
273
333
|
end
|
274
334
|
```
|
275
335
|
|
276
336
|
### `should` vs `is_expected.to`
|
277
337
|
|
278
|
-
In this README and throughout the documentation,
|
279
|
-
of RSpec's one-liner syntax over `is_expected.to`.
|
280
|
-
|
281
|
-
|
282
|
-
can do that too:
|
338
|
+
In this README and throughout the documentation, you'll notice that we use the
|
339
|
+
`should` form of RSpec's one-liner syntax over `is_expected.to`. Beside being
|
340
|
+
the namesake of the gem itself, this is our preferred syntax as it's short and
|
341
|
+
sweet. But if you prefer to use `is_expected.to`, you can do that too:
|
283
342
|
|
284
343
|
```ruby
|
285
344
|
RSpec.describe Person, type: :model do
|
@@ -289,7 +348,7 @@ end
|
|
289
348
|
|
290
349
|
## Matchers
|
291
350
|
|
292
|
-
|
351
|
+
Here is the full list of matchers that ship with this gem. If you need details
|
293
352
|
about any of them, make sure to [consult the documentation][rubydocs]!
|
294
353
|
|
295
354
|
### ActiveModel matchers
|
@@ -324,16 +383,22 @@ about any of them, make sure to [consult the documentation][rubydocs]!
|
|
324
383
|
tests your `belongs_to` associations.
|
325
384
|
* **[define_enum_for](lib/shoulda/matchers/active_record/define_enum_for_matcher.rb)**
|
326
385
|
tests usage of the `enum` macro.
|
327
|
-
* **[have_and_belong_to_many](lib/shoulda/matchers/active_record/association_matcher.rb)**
|
386
|
+
* **[have_and_belong_to_many](lib/shoulda/matchers/active_record/association_matcher.rb#L827)**
|
328
387
|
tests your `has_and_belongs_to_many` associations.
|
329
388
|
* **[have_db_column](lib/shoulda/matchers/active_record/have_db_column_matcher.rb)**
|
330
389
|
tests that the table that backs your model has a specific column.
|
331
390
|
* **[have_db_index](lib/shoulda/matchers/active_record/have_db_index_matcher.rb)**
|
332
391
|
tests that the table that backs your model has an index on a specific column.
|
333
|
-
* **[
|
392
|
+
* **[have_implicit_order_column](lib/shoulda/matchers/active_record/have_implicit_order_column.rb)**
|
393
|
+
tests usage of `implicit_order_column`.
|
394
|
+
* **[have_many](lib/shoulda/matchers/active_record/association_matcher.rb#L328)**
|
334
395
|
tests your `has_many` associations.
|
335
|
-
* **[
|
396
|
+
* **[have_many_attached](lib/shoulda/matchers/active_record/have_attached_matcher.rb)**
|
397
|
+
tests your `has_many_attached` associations.
|
398
|
+
* **[have_one](lib/shoulda/matchers/active_record/association_matcher.rb#L598)**
|
336
399
|
tests your `has_one` associations.
|
400
|
+
* **[have_one_attached](lib/shoulda/matchers/active_record/have_attached_matcher.rb)**
|
401
|
+
tests your `has_one_attached` associations.
|
337
402
|
* **[have_readonly_attribute](lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb)**
|
338
403
|
tests usage of the `attr_readonly` macro.
|
339
404
|
* **[have_rich_text](lib/shoulda/matchers/active_record/have_rich_text_matcher.rb)**
|
@@ -365,11 +430,11 @@ about any of them, make sure to [consult the documentation][rubydocs]!
|
|
365
430
|
makes assertions on the `session` hash.
|
366
431
|
* **[set_flash](lib/shoulda/matchers/action_controller/set_flash_matcher.rb)**
|
367
432
|
makes assertions on the `flash` hash.
|
368
|
-
* **[use_after_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#
|
433
|
+
* **[use_after_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L29)**
|
369
434
|
tests that an `after_action` callback is defined in your controller.
|
370
|
-
* **[use_around_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#
|
435
|
+
* **[use_around_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L75)**
|
371
436
|
tests that an `around_action` callback is defined in your controller.
|
372
|
-
* **[use_before_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#
|
437
|
+
* **[use_before_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L4)**
|
373
438
|
tests that a `before_action` callback is defined in your controller.
|
374
439
|
|
375
440
|
### Routing matchers
|
@@ -383,37 +448,53 @@ about any of them, make sure to [consult the documentation][rubydocs]!
|
|
383
448
|
tests that an object forwards messages to other, internal objects by way of
|
384
449
|
delegation.
|
385
450
|
|
386
|
-
##
|
451
|
+
## Extensions
|
387
452
|
|
388
|
-
|
389
|
-
|
453
|
+
Over time our community has created extensions to Shoulda Matchers. If you've
|
454
|
+
created something that you want to share, please [let us know][new-issue]!
|
390
455
|
|
391
|
-
|
456
|
+
* **[shoulda-matchers-cucumber]** – Adds support for using Shoulda Matchers in
|
457
|
+
Cucumber tests.
|
392
458
|
|
393
|
-
[
|
459
|
+
[new-issue]: https://github.com/thoughtbot/shoulda-matchers/issues/new
|
460
|
+
[shoulda-matchers-cucumber]: https://github.com/majioa/shoulda-matchers-cucumber
|
394
461
|
|
395
462
|
## Contributing
|
396
463
|
|
397
|
-
|
398
|
-
|
464
|
+
Have a fix for a problem you've been running into or an idea for a new feature
|
465
|
+
you think would be useful? Take a look at the [Contributing
|
466
|
+
document](CONTRIBUTING.md) for instructions on setting up the repo on your
|
467
|
+
machine, understanding the codebase, and creating a good pull request.
|
399
468
|
|
400
|
-
|
469
|
+
## Compatibility
|
470
|
+
|
471
|
+
Shoulda Matchers is tested and supported against Ruby 2.6+, Rails
|
472
|
+
5.2+, RSpec 3.x, and Minitest 5.x.
|
473
|
+
|
474
|
+
- For Ruby < 2.4 and Rails < 4.1 compatibility, please use [v3.1.3][v3.1.3].
|
475
|
+
- For Ruby < 3.0 and Rails < 6.1 compatibility, please use [v4.5.1][v4.5.1].
|
401
476
|
|
402
|
-
|
403
|
-
[
|
404
|
-
pull request.
|
477
|
+
[v3.1.3]: https://github.com/thoughtbot/shoulda-matchers/tree/v3.1.3
|
478
|
+
[v4.5.1]: https://github.com/thoughtbot/shoulda-matchers/tree/v4.5.1
|
405
479
|
|
406
480
|
## Versioning
|
407
481
|
|
408
482
|
Shoulda Matchers follows Semantic Versioning 2.0 as defined at
|
409
|
-
<
|
483
|
+
<https://semver.org>.
|
484
|
+
|
485
|
+
## Team
|
486
|
+
|
487
|
+
Shoulda Matchers is maintained by [Elliot Winkler][mcmire] and [Gui
|
488
|
+
Albuk][guialbuk].
|
489
|
+
|
490
|
+
[mcmire]: https://github.com/mcmire
|
491
|
+
[guialbuk]: https://github.com/guialbuk
|
410
492
|
|
411
|
-
## License
|
493
|
+
## Copyright/License
|
412
494
|
|
413
|
-
Shoulda Matchers is copyright © 2006-
|
414
|
-
|
415
|
-
|
416
|
-
[MIT-LICENSE](MIT-LICENSE) file.
|
495
|
+
Shoulda Matchers is copyright © 2006-2021 Tammer Saleh and [thoughtbot,
|
496
|
+
inc][thoughtbot-website]. It is free and opensource software and may be
|
497
|
+
redistributed under the terms specified in the [LICENSE](LICENSE) file.
|
417
498
|
|
418
499
|
[thoughtbot-website]: https://thoughtbot.com
|
419
500
|
|
@@ -423,8 +504,7 @@ and may be redistributed under the terms specified in the
|
|
423
504
|
|
424
505
|
[thoughtbot-logo]: https://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg
|
425
506
|
|
426
|
-
|
427
|
-
logos for thoughtbot are trademarks of thoughtbot, inc.
|
507
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
428
508
|
|
429
509
|
We are passionate about open source software. See [our other
|
430
510
|
projects][community]. We are [available for hire][hire].
|
@@ -1,64 +1,6 @@
|
|
1
1
|
module Shoulda
|
2
2
|
module Matchers
|
3
3
|
module ActionController
|
4
|
-
# The `use_before_filter` matcher is used to test that a before_filter
|
5
|
-
# callback is defined within your controller.
|
6
|
-
#
|
7
|
-
# class UsersController < ApplicationController
|
8
|
-
# before_filter :authenticate_user!
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# # RSpec
|
12
|
-
# RSpec.describe UsersController, type: :controller do
|
13
|
-
# it { should use_before_filter(:authenticate_user!) }
|
14
|
-
# it { should_not use_before_filter(:prevent_ssl) }
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# # Minitest (Shoulda)
|
18
|
-
# class UsersControllerTest < ActionController::TestCase
|
19
|
-
# should use_before_filter(:authenticate_user!)
|
20
|
-
# should_not use_before_filter(:prevent_ssl)
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# @note This method is only available when using shoulda-matchers under
|
24
|
-
# Rails 4.x.
|
25
|
-
# @return [CallbackMatcher]
|
26
|
-
#
|
27
|
-
if RailsShim.action_pack_lt_5?
|
28
|
-
def use_before_filter(callback)
|
29
|
-
CallbackMatcher.new(callback, :before, :filter)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# The `use_after_filter` matcher is used to test that an after_filter
|
34
|
-
# callback is defined within your controller.
|
35
|
-
#
|
36
|
-
# class IssuesController < ApplicationController
|
37
|
-
# after_filter :log_activity
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# # RSpec
|
41
|
-
# RSpec.describe IssuesController, type: :controller do
|
42
|
-
# it { should use_after_filter(:log_activity) }
|
43
|
-
# it { should_not use_after_filter(:destroy_user) }
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# # Minitest (Shoulda)
|
47
|
-
# class IssuesControllerTest < ActionController::TestCase
|
48
|
-
# should use_after_filter(:log_activity)
|
49
|
-
# should_not use_after_filter(:destroy_user)
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# @note This method is only available when using shoulda-matchers under
|
53
|
-
# Rails 4.x.
|
54
|
-
# @return [CallbackMatcher]
|
55
|
-
#
|
56
|
-
if RailsShim.action_pack_lt_5?
|
57
|
-
def use_after_filter(callback)
|
58
|
-
CallbackMatcher.new(callback, :after, :filter)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
4
|
# The `use_before_action` matcher is used to test that a before_action
|
63
5
|
# callback is defined within your controller.
|
64
6
|
#
|
@@ -109,35 +51,6 @@ module Shoulda
|
|
109
51
|
CallbackMatcher.new(callback, :after, :action)
|
110
52
|
end
|
111
53
|
|
112
|
-
# The `use_around_filter` matcher is used to test that an around_filter
|
113
|
-
# callback is defined within your controller.
|
114
|
-
#
|
115
|
-
# class ChangesController < ApplicationController
|
116
|
-
# around_filter :wrap_in_transaction
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# # RSpec
|
120
|
-
# RSpec.describe ChangesController, type: :controller do
|
121
|
-
# it { should use_around_filter(:wrap_in_transaction) }
|
122
|
-
# it { should_not use_around_filter(:save_view_context) }
|
123
|
-
# end
|
124
|
-
#
|
125
|
-
# # Minitest (Shoulda)
|
126
|
-
# class ChangesControllerTest < ActionController::TestCase
|
127
|
-
# should use_around_filter(:wrap_in_transaction)
|
128
|
-
# should_not use_around_filter(:save_view_context)
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# @note This method is only available when using shoulda-matchers under
|
132
|
-
# Rails 4.x.
|
133
|
-
# @return [CallbackMatcher]
|
134
|
-
#
|
135
|
-
if RailsShim.action_pack_lt_5?
|
136
|
-
def use_around_filter(callback)
|
137
|
-
CallbackMatcher.new(callback, :around, :filter)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
54
|
# The `use_around_action` matcher is used to test that an around_action
|
142
55
|
# callback is defined within your controller.
|
143
56
|
#
|
@@ -179,11 +92,13 @@ module Shoulda
|
|
179
92
|
end
|
180
93
|
|
181
94
|
def failure_message
|
182
|
-
"Expected that #{controller_class.name} would have :#{method_name}
|
95
|
+
"Expected that #{controller_class.name} would have :#{method_name}"\
|
96
|
+
" as a #{kind}_#{callback_type}"
|
183
97
|
end
|
184
98
|
|
185
99
|
def failure_message_when_negated
|
186
|
-
"Expected that #{controller_class.name} would not have
|
100
|
+
"Expected that #{controller_class.name} would not have"\
|
101
|
+
" :#{method_name} as a #{kind}_#{callback_type}"
|
187
102
|
end
|
188
103
|
|
189
104
|
def description
|