shoulda-matchers 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -3
- data/CONTRIBUTING.md +60 -28
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -12
- data/NEWS.md +111 -0
- data/README.md +94 -6
- data/Rakefile +10 -8
- data/custom_plan.rb +88 -0
- data/gemfiles/4.0.0.gemfile +1 -0
- data/gemfiles/4.0.0.gemfile.lock +21 -18
- data/gemfiles/4.0.1.gemfile +1 -0
- data/gemfiles/4.0.1.gemfile.lock +21 -18
- data/gemfiles/4.1.gemfile +1 -0
- data/gemfiles/4.1.gemfile.lock +21 -18
- data/gemfiles/4.2.gemfile +1 -0
- data/gemfiles/4.2.gemfile.lock +24 -21
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +6 -11
- data/lib/shoulda/matchers/active_model.rb +10 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +258 -180
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +236 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +34 -14
- data/lib/shoulda/matchers/active_model/helpers.rb +9 -17
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +13 -6
- data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +13 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +19 -35
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +13 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +12 -2
- data/lib/shoulda/matchers/active_model/qualifiers.rb +12 -0
- data/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +30 -32
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +5 -8
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -22
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +27 -16
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +58 -15
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +22 -12
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +165 -87
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +7 -9
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +111 -49
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +60 -0
- data/lib/shoulda/matchers/active_model/validator.rb +71 -52
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +19 -5
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +450 -124
- data/lib/shoulda/matchers/util.rb +43 -0
- data/lib/shoulda/matchers/util/word_wrap.rb +59 -31
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/update_gem_in_all_appraisals +1 -1
- data/script/update_gems_in_all_appraisals +1 -1
- data/spec/acceptance/multiple_libraries_integration_spec.rb +5 -2
- data/spec/acceptance/rails_integration_spec.rb +6 -2
- data/spec/spec_helper.rb +1 -3
- data/spec/support/acceptance/helpers/step_helpers.rb +4 -1
- data/spec/support/tests/current_bundle.rb +21 -7
- data/spec/support/unit/active_record/create_table.rb +54 -0
- data/spec/support/unit/attribute.rb +47 -0
- data/spec/support/unit/capture.rb +6 -0
- data/spec/support/unit/change_value.rb +111 -0
- data/spec/support/unit/create_model_arguments/basic.rb +135 -0
- data/spec/support/unit/create_model_arguments/has_many.rb +15 -0
- data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +74 -0
- data/spec/support/unit/helpers/active_record_versions.rb +1 -1
- data/spec/support/unit/helpers/class_builder.rb +61 -47
- data/spec/support/unit/helpers/database_helpers.rb +5 -3
- data/spec/support/unit/helpers/model_builder.rb +77 -97
- data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +44 -0
- data/spec/support/unit/load_environment.rb +12 -0
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +2 -2
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +12 -1
- data/spec/support/unit/model_creation_strategies/active_model.rb +111 -0
- data/spec/support/unit/model_creation_strategies/active_record.rb +77 -0
- data/spec/support/unit/model_creators.rb +19 -0
- data/spec/support/unit/model_creators/active_model.rb +39 -0
- data/spec/support/unit/model_creators/active_record.rb +43 -0
- data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +95 -0
- data/spec/support/unit/model_creators/active_record/has_many.rb +67 -0
- data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +42 -0
- data/spec/support/unit/model_creators/basic.rb +97 -0
- data/spec/support/unit/rails_application.rb +1 -1
- data/spec/support/unit/record_validating_confirmation_builder.rb +3 -7
- data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +79 -0
- data/spec/support/unit/validation_matcher_scenario.rb +62 -0
- data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +4 -0
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +575 -140
- data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +115 -15
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +42 -4
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +92 -6
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +122 -10
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +306 -58
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +122 -3
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +805 -131
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +196 -29
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +82 -40
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +600 -101
- data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +88 -33
- data/spec/unit_spec_helper.rb +10 -22
- data/zeus.json +11 -0
- metadata +64 -23
- data/lib/shoulda/matchers/active_model/strict_validator.rb +0 -51
- data/spec/support/unit/shared_examples/numerical_type_submatcher.rb +0 -15
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +0 -288
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +0 -100
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +0 -100
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 958afbf8d323fd9b923340fdffc6156b7a3249cc
|
4
|
+
data.tar.gz: d20c30587592682f62e4b061619d32254625de23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2141dd710f58fa62201e4fa3de70c324bbb9e6d225f41d88ecef413c401a10f1426f59025849e466c58d7c58bf6f94b0330b6e82c7577e3797f6bd0f91d97a2
|
7
|
+
data.tar.gz: d22c37a1994c433c9213b1a3090f6cd06201a49d19fbc7cdbeca7bc826fec4b0853a7a216e8977df578b1627011eb23786fe276dc12e2a906116822dd88f0f1b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,24 +1,56 @@
|
|
1
|
+
# Contributing to shoulda-matchers
|
2
|
+
|
1
3
|
We love contributions from the community! Here's a quick guide to making a pull
|
2
4
|
request.
|
3
5
|
|
4
|
-
|
6
|
+
1. If you haven't contributed before, please read and understand the [Code of
|
7
|
+
Conduct].
|
8
|
+
|
9
|
+
1. Ensure that you have a [working Ruby environment].
|
10
|
+
|
11
|
+
1. Fork the repo on GitHub, then clone it to your machine.
|
12
|
+
|
13
|
+
1. Now that you've cloned the repo, navigate to it and install dependencies by
|
14
|
+
running:
|
5
15
|
|
6
|
-
|
7
|
-
|
16
|
+
```
|
17
|
+
bundle install
|
18
|
+
```
|
8
19
|
|
9
|
-
1.
|
20
|
+
1. All tests should be passing, but it's a good idea to run them anyway
|
21
|
+
before starting any work:
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle exec rake
|
25
|
+
```
|
10
26
|
|
11
|
-
|
27
|
+
1. If you're adding functionality or fixing a bug, you'll want to add a
|
28
|
+
failing test for the issue first.
|
12
29
|
|
13
|
-
|
14
|
-
to know that you have a clean slate: `bundle && bundle exec rake`
|
30
|
+
1. Now you can implement the feature or bugfix.
|
15
31
|
|
16
|
-
|
17
|
-
|
32
|
+
1. Since we only accept pull requests with passing tests, it's a good idea to
|
33
|
+
run the tests again. Since you're probably working on a single file, you can
|
34
|
+
run the tests for that file with the following command:
|
18
35
|
|
19
|
-
|
36
|
+
```
|
37
|
+
appraisal 4.2 rspec <path of test file to run>
|
38
|
+
```
|
20
39
|
|
21
|
-
|
40
|
+
You can also run unit tests by running `zeus start` in one shell, and then
|
41
|
+
running the following in another:
|
42
|
+
|
43
|
+
```
|
44
|
+
zeus rspec <path of test file to run>
|
45
|
+
```
|
46
|
+
|
47
|
+
And to run the entire test suite again:
|
48
|
+
|
49
|
+
```
|
50
|
+
bundle exec rake
|
51
|
+
```
|
52
|
+
|
53
|
+
1. Finally, push to your fork and submit a pull request.
|
22
54
|
|
23
55
|
At this point you're waiting on us. We try to respond to issues and pull
|
24
56
|
requests within a few business days. We may suggest some changes to make to your
|
@@ -26,35 +58,27 @@ code to fit with our [code style] or the project style, or discuss alternate
|
|
26
58
|
ways of addressing the issue in question. When we're happy with everything,
|
27
59
|
we'll bring your changes into master. Now you're a contributor!
|
28
60
|
|
29
|
-
##
|
61
|
+
## Addendum: Setting up your environment
|
30
62
|
|
31
|
-
###
|
63
|
+
### Installing dependencies (Linux only)
|
32
64
|
|
33
|
-
|
34
|
-
sudo apt-get install -y ruby-dev libpq-dev libsqlite3-dev nodejs
|
35
|
-
```
|
65
|
+
#### Debian/Ubuntu
|
36
66
|
|
37
|
-
|
38
|
-
with Ruby 2, so use your Ruby version manager of choice to install the latest
|
39
|
-
version of Ruby (2.2.1 at the time of this writing).
|
67
|
+
Run this command to install necessary dependencies:
|
40
68
|
|
41
69
|
```
|
42
|
-
|
43
|
-
rvm install 2.2
|
44
|
-
rvm use 2.2
|
45
|
-
|
46
|
-
# rbenv
|
47
|
-
rbenv install 2.2.1
|
48
|
-
rbenv shell 2.2.1
|
70
|
+
sudo apt-get install -y ruby-dev libpq-dev libsqlite3-dev nodejs
|
49
71
|
```
|
50
72
|
|
51
|
-
|
73
|
+
#### RedHat
|
74
|
+
|
75
|
+
Run this command to install necessary dependencies:
|
52
76
|
|
53
77
|
```
|
54
78
|
sudo yum install -y ruby-devel postgresql-devel sqlite-devel zlib-devel
|
55
79
|
```
|
56
80
|
|
57
|
-
|
81
|
+
Then, install one of the JavaScript runtimes supported by [execjs]. For
|
58
82
|
instance, to install node.js:
|
59
83
|
|
60
84
|
```
|
@@ -63,6 +87,14 @@ curl -sL https://rpm.nodesource.com/setup | bash -
|
|
63
87
|
yum install -y nodejs
|
64
88
|
```
|
65
89
|
|
90
|
+
### Installing Ruby (all platforms)
|
91
|
+
|
92
|
+
shoulda-matchers is only compatible with Ruby 2.x. A `.ruby-version` is included
|
93
|
+
in the repo, so if you're using one of the Ruby version manager tools, then you
|
94
|
+
should be using (or have been prompted to install) the latest version of Ruby.
|
95
|
+
If not, you'll want to do that.
|
96
|
+
|
97
|
+
[working Ruby environment]: #addendum-setting-up-your-environment
|
66
98
|
[Code of Conduct]: https://thoughtbot.com/open-source-code-of-conduct
|
67
99
|
[code style]: https://github.com/thoughtbot/guides/tree/master/style
|
68
100
|
[execjs]: https://github.com/sstephenson/execjs
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -30,23 +30,25 @@ GEM
|
|
30
30
|
yajl-ruby (~> 1.1.0)
|
31
31
|
rake (10.4.2)
|
32
32
|
redcarpet (3.0.0)
|
33
|
-
rspec (3.
|
34
|
-
rspec-core (~> 3.
|
35
|
-
rspec-expectations (~> 3.
|
36
|
-
rspec-mocks (~> 3.
|
37
|
-
rspec-core (3.
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-expectations (3.
|
33
|
+
rspec (3.4.0)
|
34
|
+
rspec-core (~> 3.4.0)
|
35
|
+
rspec-expectations (~> 3.4.0)
|
36
|
+
rspec-mocks (~> 3.4.0)
|
37
|
+
rspec-core (3.4.1)
|
38
|
+
rspec-support (~> 3.4.0)
|
39
|
+
rspec-expectations (3.4.0)
|
40
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-mocks (3.
|
41
|
+
rspec-support (~> 3.4.0)
|
42
|
+
rspec-mocks (3.4.0)
|
43
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-support (3.
|
44
|
+
rspec-support (~> 3.4.0)
|
45
|
+
rspec-support (3.4.1)
|
46
46
|
slop (3.6.0)
|
47
47
|
thor (0.19.1)
|
48
48
|
yajl-ruby (1.1.0)
|
49
49
|
yard (0.8.7.3)
|
50
|
+
zeus (0.15.4)
|
51
|
+
method_source (>= 0.6.7)
|
50
52
|
|
51
53
|
PLATFORMS
|
52
54
|
ruby
|
@@ -62,6 +64,7 @@ DEPENDENCIES
|
|
62
64
|
redcarpet
|
63
65
|
rspec (~> 3.2)
|
64
66
|
yard
|
67
|
+
zeus
|
65
68
|
|
66
69
|
BUNDLED WITH
|
67
|
-
1.
|
70
|
+
1.11.1
|
data/NEWS.md
CHANGED
@@ -1,3 +1,114 @@
|
|
1
|
+
# 3.1.0
|
2
|
+
|
3
|
+
### Bug fixes
|
4
|
+
|
5
|
+
* Update `validate_numericality_of` so that submatchers are applied lazily
|
6
|
+
instead of immediately. Previously, qualifiers were order-dependent, meaning
|
7
|
+
that if you used `strict` before you used, say, `odd`, then `strict` wouldn't
|
8
|
+
actually apply to `odd`. Now the order that you specify qualifiers doesn't
|
9
|
+
matter.
|
10
|
+
|
11
|
+
* *Source: [6c67a5e]*
|
12
|
+
|
13
|
+
* Fix `allow_value` so that it does not raise an AttributeChangedValueError
|
14
|
+
(formerly CouldNotSetAttributeError) when used against an attribute that is an
|
15
|
+
enum in an ActiveRecord model.
|
16
|
+
|
17
|
+
* *Source: [9e8603e]*
|
18
|
+
|
19
|
+
* Add a `ignoring_interference_by_writer` qualifier to all matchers, not just
|
20
|
+
`allow_value`. *This is enabled by default, which means that you should never
|
21
|
+
get a CouldNotSetAttributeError again.* (You may get some more information if
|
22
|
+
a test fails, however.)
|
23
|
+
|
24
|
+
* *Source: [1189934], [5532f43]*
|
25
|
+
* *Fixes: [#786], [#799], [#801], [#804], [#817], [#841], [#849], [#872],
|
26
|
+
[#873], and [#874]*
|
27
|
+
|
28
|
+
* Fix `validate_numericality_of` so that it does not blow up when used against
|
29
|
+
a virtual attribute defined in an ActiveRecord model (that is, an attribute
|
30
|
+
that is not present in the database but is defined using `attr_accessor`).
|
31
|
+
|
32
|
+
* *Source: [#822]*
|
33
|
+
|
34
|
+
* Update `validate_numericality_of` so that it no longer raises an
|
35
|
+
IneffectiveTestError if used against a numeric column.
|
36
|
+
|
37
|
+
* *Source: [5ed0362]*
|
38
|
+
* *Fixes: [#832]*
|
39
|
+
|
40
|
+
[6c67a5e]: https://github.com/thoughtbot/shoulda-matchers/commit/6c67a5eb0df265d3a565aa7d1a7e2b645051eb5a
|
41
|
+
[9e8603e]: https://github.com/thoughtbot/shoulda-matchers/commit/9e8603eb745bfa2a5aea6dfef85adf680d447151
|
42
|
+
[1189934]: https://github.com/thoughtbot/shoulda-matchers/commit/118993480604d39c73687d069f7af3726f3e3f3e
|
43
|
+
[5532f43]: https://github.com/thoughtbot/shoulda-matchers/commit/5532f4359aa332b10de7d46f876eaffd4a95b5b6
|
44
|
+
[#786]: https://github.com/thoughtbot/shoulda-matchers/issues/786
|
45
|
+
[#799]: https://github.com/thoughtbot/shoulda-matchers/issues/799
|
46
|
+
[#801]: https://github.com/thoughtbot/shoulda-matchers/issues/801
|
47
|
+
[#804]: https://github.com/thoughtbot/shoulda-matchers/issues/804
|
48
|
+
[#817]: https://github.com/thoughtbot/shoulda-matchers/issues/817
|
49
|
+
[#841]: https://github.com/thoughtbot/shoulda-matchers/issues/841
|
50
|
+
[#849]: https://github.com/thoughtbot/shoulda-matchers/issues/849
|
51
|
+
[#872]: https://github.com/thoughtbot/shoulda-matchers/issues/872
|
52
|
+
[#873]: https://github.com/thoughtbot/shoulda-matchers/issues/873
|
53
|
+
[#874]: https://github.com/thoughtbot/shoulda-matchers/issues/874
|
54
|
+
[#822]: https://github.com/thoughtbot/shoulda-matchers/pull/822
|
55
|
+
[5ed0362]: https://github.com/thoughtbot/shoulda-matchers/commit/5ed03624197314865ff5463e473e5e84bb91d9ea
|
56
|
+
[#832]: https://github.com/thoughtbot/shoulda-matchers/issues/832
|
57
|
+
|
58
|
+
### Features
|
59
|
+
|
60
|
+
* Add a new qualifier, `ignoring_case_sensitivity`, to `validate_uniqueness_of`.
|
61
|
+
This provides a way to test uniqueness of an attribute whose case is
|
62
|
+
normalized, either in a custom writer method for that attribute, or in a
|
63
|
+
custom `before_validation` callback.
|
64
|
+
|
65
|
+
* *Source: [#840]*
|
66
|
+
* *Fixes: [#836]*
|
67
|
+
|
68
|
+
[#840]: https://github.com/thoughtbot/shoulda-matchers/pull/840
|
69
|
+
[#836]: https://github.com/thoughtbot/shoulda-matchers/issues/836
|
70
|
+
|
71
|
+
### Improvements
|
72
|
+
|
73
|
+
* Improve failure messages and descriptions of all matchers across the board so
|
74
|
+
that it is easier to understand what the matcher was doing when it failed.
|
75
|
+
(You'll see a huge difference in the output of the numericality and uniqueness
|
76
|
+
matchers in particular.)
|
77
|
+
|
78
|
+
* Matchers now raise an error if any attributes that the matcher is attempting
|
79
|
+
to set do not exist on the model.
|
80
|
+
|
81
|
+
* *Source: [2962112]*
|
82
|
+
|
83
|
+
* Update `validate_numericality_of` so that it doesn't always run all of the
|
84
|
+
submatchers, but stops on the first one that fails. Since failure messages
|
85
|
+
now contain information as to what value the matcher set on the attribute when
|
86
|
+
it failed, this change guarantees that the correct value will be shown.
|
87
|
+
|
88
|
+
* *Source: [8e24a6e]*
|
89
|
+
|
90
|
+
* Continue to detect if attributes change incoming values, but now instead of
|
91
|
+
immediately seeing a CouldNotSetAttributeError, you will only be informed
|
92
|
+
about it if the test you've written fails.
|
93
|
+
|
94
|
+
* *Source: [1189934]*
|
95
|
+
|
96
|
+
* Add an additional check to `define_enum_for` to ensure that the column that
|
97
|
+
underlies the enum attribute you're testing is an integer column.
|
98
|
+
|
99
|
+
* *Source: [68dd70a]*
|
100
|
+
|
101
|
+
* Add a test for `validate_numericality_of` so that it officially supports money
|
102
|
+
columns.
|
103
|
+
|
104
|
+
* *Source: [a559713]*
|
105
|
+
* *Refs: [#841]*
|
106
|
+
|
107
|
+
[2962112]: https://github.com/thoughtbot/shoulda-matchers/commit/296211211497e624dde87adae68b385ad4cdae3a
|
108
|
+
[8e24a6e]: https://github.com/thoughtbot/shoulda-matchers/commit/8e24a6e9b2b147f2c51fb03aa02543f213acab34
|
109
|
+
[68dd70a]: https://github.com/thoughtbot/shoulda-matchers/commit/68dd70a23d8997a490683adcd2108a4a5cadf8ba
|
110
|
+
[a559713]: https://github.com/thoughtbot/shoulda-matchers/commit/a559713f96303414551c0bc1767fb11eb19bcc5d
|
111
|
+
|
1
112
|
# 3.0.1
|
2
113
|
|
3
114
|
### Bug fixes
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ complex, and error-prone.
|
|
97
97
|
tests that an object forwards messages to other, internal objects by way of
|
98
98
|
delegation.
|
99
99
|
|
100
|
-
##
|
100
|
+
## Getting started
|
101
101
|
|
102
102
|
### RSpec
|
103
103
|
|
@@ -120,6 +120,42 @@ describe Person do
|
|
120
120
|
end
|
121
121
|
```
|
122
122
|
|
123
|
+
#### Availability of matchers in various example groups
|
124
|
+
|
125
|
+
Since shoulda-matchers provides four categories of matchers, there are four
|
126
|
+
different levels where you can use these matchers:
|
127
|
+
|
128
|
+
* ActiveRecord and ActiveModel matchers are available only in model example
|
129
|
+
groups, i.e., those tagged with `type: :model` or in files located under
|
130
|
+
`spec/models`.
|
131
|
+
* ActionController matchers are available only in controller example groups,
|
132
|
+
i.e., those tagged with `type: :controller` or in files located under
|
133
|
+
`spec/controllers`.
|
134
|
+
* The `route` matcher is available also in routing example groups, i.e., those
|
135
|
+
tagged with `type: :routing` or in files located under `spec/routing`.
|
136
|
+
* Independent matchers are available in all example groups.
|
137
|
+
|
138
|
+
**If you are using ActiveModel or ActiveRecord outside of Rails** and you want
|
139
|
+
to use model matchers in certain example groups, you'll need to manually include
|
140
|
+
them. Here's a good way of doing that:
|
141
|
+
|
142
|
+
``` ruby
|
143
|
+
RSpec.configure do |config|
|
144
|
+
config.include(Shoulda::Matchers::ActiveModel, type: :model)
|
145
|
+
config.include(Shoulda::Matchers::ActiveRecord, type: :model)
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
Then you can say:
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
describe MyModel, type: :model do
|
153
|
+
# ...
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
#### `should` vs `is_expected.to`
|
158
|
+
|
123
159
|
Note that in this README and throughout the documentation we're using the
|
124
160
|
`should` form of RSpec's one-liner syntax over `is_expected.to`. The `should`
|
125
161
|
form works regardless of how you've configured RSpec -- meaning you can still
|
@@ -136,12 +172,15 @@ end
|
|
136
172
|
|
137
173
|
Shoulda Matchers was originally a component of [Shoulda][shoulda], a gem that
|
138
174
|
also provides `should` and `context` syntax via
|
139
|
-
[`shoulda-context`][shoulda-context].
|
140
|
-
|
175
|
+
[`shoulda-context`][shoulda-context].
|
176
|
+
|
177
|
+
At the moment, `shoulda` has not been updated to support `shoulda-matchers` 3.0,
|
178
|
+
so you'll want to add the following to your Gemfile:
|
141
179
|
|
142
180
|
```ruby
|
143
181
|
group :test do
|
144
182
|
gem 'shoulda', '~> 3.5'
|
183
|
+
gem 'shoulda-matchers', '~> 2.0'
|
145
184
|
end
|
146
185
|
```
|
147
186
|
|
@@ -164,7 +203,8 @@ Before you can use Shoulda Matchers, you'll need to tell it a couple of things:
|
|
164
203
|
* Which portion of the matchers you want to use
|
165
204
|
|
166
205
|
You can supply this information by using a configuration block. Place the
|
167
|
-
following in
|
206
|
+
following in `rails_helper.rb` (if you're using RSpec) or `test_helper.rb` (if
|
207
|
+
you're using Minitest):
|
168
208
|
|
169
209
|
``` ruby
|
170
210
|
Shoulda::Matchers.configure do |config|
|
@@ -185,6 +225,52 @@ Shoulda::Matchers.configure do |config|
|
|
185
225
|
end
|
186
226
|
```
|
187
227
|
|
228
|
+
## Running tests
|
229
|
+
|
230
|
+
### Unit tests
|
231
|
+
|
232
|
+
Unit tests are the most common kind of tests in this gem, and the best way to
|
233
|
+
run them is by using [Zeus].
|
234
|
+
|
235
|
+
You'll want to run `zeus start` in one shell, then in another shell, instead of
|
236
|
+
using `rspec` to run tests, you can use `zeus rspec`. So for instance, you might
|
237
|
+
say:
|
238
|
+
|
239
|
+
```
|
240
|
+
zeus rspec spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb
|
241
|
+
```
|
242
|
+
|
243
|
+
As a shortcut, you can also drop the initial part of the path and say this
|
244
|
+
instead:
|
245
|
+
|
246
|
+
```
|
247
|
+
zeus rspec active_model/validate_inclusion_of_matcher_spec.rb
|
248
|
+
```
|
249
|
+
|
250
|
+
### Acceptance tests
|
251
|
+
|
252
|
+
The gem uses [Appraisal] to test against multiple versions of Rails and Ruby.
|
253
|
+
This means that if you're trying to run a single test file, you'll need to
|
254
|
+
specify which appraisal to use. For instance, you can't simply say:
|
255
|
+
|
256
|
+
```
|
257
|
+
rspec spec/acceptance/active_model_integration_spec.rb
|
258
|
+
```
|
259
|
+
|
260
|
+
Instead, you need to say
|
261
|
+
|
262
|
+
```
|
263
|
+
bundle exec appraisal 4.2 rspec spec/acceptance/active_model_integration_spec.rb
|
264
|
+
```
|
265
|
+
|
266
|
+
### All tests
|
267
|
+
|
268
|
+
You can run all tests by saying:
|
269
|
+
|
270
|
+
```
|
271
|
+
bundle exec rake
|
272
|
+
```
|
273
|
+
|
188
274
|
## Generating documentation
|
189
275
|
|
190
276
|
YARD is used to generate documentation, which can be viewed [online][rubydocs].
|
@@ -212,7 +298,7 @@ pull request.
|
|
212
298
|
## Compatibility
|
213
299
|
|
214
300
|
Shoulda Matchers is tested and supported against Rails 4.x, RSpec 3.x, Minitest
|
215
|
-
5, and Ruby 2.x.
|
301
|
+
5, Minitest 4, and Ruby 2.x.
|
216
302
|
|
217
303
|
## Versioning
|
218
304
|
|
@@ -221,7 +307,7 @@ Shoulda Matchers follows Semantic Versioning 2.0 as defined at
|
|
221
307
|
|
222
308
|
## License
|
223
309
|
|
224
|
-
Shoulda Matchers is copyright © 2006-
|
310
|
+
Shoulda Matchers is copyright © 2006-2016
|
225
311
|
[thoughtbot, inc](https://thoughtbot.com/). It is free software,
|
226
312
|
and may be redistributed under the terms specified in the
|
227
313
|
[MIT-LICENSE](MIT-LICENSE) file.
|
@@ -248,3 +334,5 @@ We are [available for hire][hire].
|
|
248
334
|
[contributors]: https://github.com/thoughtbot/shoulda-matchers/contributors
|
249
335
|
[shoulda]: http://github.com/thoughtbot/shoulda
|
250
336
|
[shoulda-context]: http://github.com/thoughtbot/shoulda-context
|
337
|
+
[Zeus]: https://github.com/burke/zeus
|
338
|
+
[Appraisal]: https://github.com/thoughtbot/appraisal
|