shoulda-matchers 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -7
- data/.travis.yml +4 -0
- data/Appraisals +8 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +77 -66
- data/MIT-LICENSE +1 -1
- data/NEWS.md +63 -1
- data/README.md +189 -33
- data/Rakefile +6 -5
- data/features/rails_integration.feature +1 -1
- data/features/step_definitions/rails_steps.rb +7 -6
- data/gemfiles/3.0.gemfile +2 -2
- data/gemfiles/3.0.gemfile.lock +14 -5
- data/gemfiles/3.1.gemfile +2 -2
- data/gemfiles/3.1.gemfile.lock +14 -5
- data/gemfiles/3.2.gemfile +2 -2
- data/gemfiles/3.2.gemfile.lock +16 -7
- data/gemfiles/4.0.0.gemfile +2 -2
- data/gemfiles/4.0.0.gemfile.lock +15 -6
- data/gemfiles/4.0.1.gemfile +2 -2
- data/gemfiles/4.0.1.gemfile.lock +15 -6
- data/gemfiles/4.1.gemfile +19 -0
- data/gemfiles/4.1.gemfile.lock +176 -0
- data/lib/shoulda/matchers.rb +17 -1
- data/lib/shoulda/matchers/action_controller.rb +4 -2
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +100 -0
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +4 -4
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
- data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
- data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +2 -1
- data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +167 -0
- data/lib/shoulda/matchers/active_model.rb +4 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +23 -5
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +0 -4
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +66 -14
- data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +8 -8
- data/lib/shoulda/matchers/active_model/errors.rb +40 -0
- data/lib/shoulda/matchers/active_model/helpers.rb +6 -6
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +33 -14
- data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +26 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/{odd_even_number_matcher.rb → numeric_type_matcher.rb} +9 -20
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +26 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +5 -21
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +71 -22
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +6 -1
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +25 -6
- data/lib/shoulda/matchers/active_record.rb +1 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +67 -13
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +40 -0
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +24 -1
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
- data/lib/shoulda/matchers/assertion_error.rb +7 -2
- data/lib/shoulda/matchers/error.rb +24 -0
- data/lib/shoulda/matchers/independent.rb +10 -0
- data/lib/shoulda/matchers/independent/delegate_matcher.rb +157 -0
- data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +34 -0
- data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +36 -0
- data/lib/shoulda/matchers/integrations/rspec.rb +13 -14
- data/lib/shoulda/matchers/integrations/test_unit.rb +11 -9
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +7 -0
- data/shoulda-matchers.gemspec +2 -1
- data/spec/shoulda/matchers/action_controller/callback_matcher_spec.rb +79 -0
- data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +3 -3
- data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +11 -11
- data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +21 -21
- data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +10 -10
- data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +45 -18
- data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +8 -8
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +19 -19
- data/spec/shoulda/matchers/action_controller/route_params_spec.rb +6 -6
- data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +11 -11
- data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +44 -44
- data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +205 -0
- data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +24 -24
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +37 -37
- data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +17 -21
- data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +24 -24
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +173 -67
- data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +40 -40
- data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +20 -20
- data/spec/shoulda/matchers/active_model/helpers_spec.rb +27 -25
- data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +126 -13
- data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
- data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +27 -26
- data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +15 -15
- data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +8 -8
- data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +9 -9
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +229 -44
- data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +44 -25
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +110 -62
- data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +19 -19
- data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +30 -30
- data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +378 -192
- data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +4 -0
- data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +33 -33
- data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +21 -17
- data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +8 -8
- data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +14 -14
- data/spec/shoulda/matchers/independent/delegate_matcher/stubbed_target_spec.rb +43 -0
- data/spec/shoulda/matchers/independent/delegate_matcher_spec.rb +184 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/activemodel_helpers.rb +2 -2
- data/spec/support/capture_helpers.rb +19 -0
- data/spec/support/controller_builder.rb +22 -3
- data/spec/support/fail_with_message_including_matcher.rb +33 -0
- data/spec/support/model_builder.rb +1 -1
- data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
- data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
- data/spec/support/test_application.rb +23 -0
- metadata +90 -22
- checksums.yaml +0 -7
- data/spec/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher_spec.rb +0 -97
- data/spec/support/shared_examples/numerical_submatcher_spec.rb +0 -23
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -20,12 +20,16 @@ matrix:
|
|
20
20
|
gemfile: gemfiles/4.0.0.gemfile
|
21
21
|
- rvm: 1.9.3
|
22
22
|
gemfile: gemfiles/4.0.1.gemfile
|
23
|
+
- rvm: 1.9.3
|
24
|
+
gemfile: gemfiles/4.1.gemfile
|
23
25
|
- rvm: 2.0.0
|
24
26
|
gemfile: gemfiles/3.2.gemfile
|
25
27
|
- rvm: 2.0.0
|
26
28
|
gemfile: gemfiles/4.0.0.gemfile
|
27
29
|
- rvm: 2.0.0
|
28
30
|
gemfile: gemfiles/4.0.1.gemfile
|
31
|
+
- rvm: 2.0.0
|
32
|
+
gemfile: gemfiles/4.1.gemfile
|
29
33
|
- rvm: rbx-19mode
|
30
34
|
gemfile: gemfiles/3.2.gemfile
|
31
35
|
- rvm: jruby-19mode
|
data/Appraisals
CHANGED
@@ -43,3 +43,11 @@ appraise '4.0.1' do
|
|
43
43
|
gem 'sass-rails', '4.0.1'
|
44
44
|
gem 'bcrypt-ruby', '~> 3.1.2'
|
45
45
|
end
|
46
|
+
|
47
|
+
appraise '4.1' do
|
48
|
+
instance_eval(&rails_4_0)
|
49
|
+
gem 'rails', '~> 4.1.0'
|
50
|
+
gem 'sass-rails', '4.0.3'
|
51
|
+
gem 'bcrypt-ruby', '~> 3.1.2'
|
52
|
+
gem "protected_attributes", '~> 1.0.6'
|
53
|
+
end
|
data/CONTRIBUTING.md
CHANGED
@@ -3,7 +3,7 @@ We love pull requests. Here's a quick guide:
|
|
3
3
|
1. Fork the repo.
|
4
4
|
|
5
5
|
2. Run the tests. We only take pull requests with passing tests, and it's great
|
6
|
-
to know that you have a clean slate: `bundle && rake`
|
6
|
+
to know that you have a clean slate: `bundle && bundle exec rake`
|
7
7
|
|
8
8
|
3. Add a test for your change. Only refactoring and documentation changes
|
9
9
|
require no new tests. If you are adding functionality or fixing a bug, we need
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,76 +1,84 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shoulda-matchers (2.
|
4
|
+
shoulda-matchers (2.6.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionmailer (3.2.
|
11
|
-
actionpack (= 3.2.
|
12
|
-
mail (~> 2.
|
13
|
-
actionpack (3.2.
|
14
|
-
activemodel (= 3.2.
|
15
|
-
activesupport (= 3.2.
|
10
|
+
actionmailer (3.2.16)
|
11
|
+
actionpack (= 3.2.16)
|
12
|
+
mail (~> 2.5.4)
|
13
|
+
actionpack (3.2.16)
|
14
|
+
activemodel (= 3.2.16)
|
15
|
+
activesupport (= 3.2.16)
|
16
16
|
builder (~> 3.0.0)
|
17
17
|
erubis (~> 2.7.0)
|
18
18
|
journey (~> 1.0.4)
|
19
|
-
rack (~> 1.4.
|
19
|
+
rack (~> 1.4.5)
|
20
20
|
rack-cache (~> 1.2)
|
21
21
|
rack-test (~> 0.6.1)
|
22
22
|
sprockets (~> 2.2.1)
|
23
|
-
activemodel (3.2.
|
24
|
-
activesupport (= 3.2.
|
23
|
+
activemodel (3.2.16)
|
24
|
+
activesupport (= 3.2.16)
|
25
25
|
builder (~> 3.0.0)
|
26
|
-
activerecord (3.2.
|
27
|
-
activemodel (= 3.2.
|
28
|
-
activesupport (= 3.2.
|
26
|
+
activerecord (3.2.16)
|
27
|
+
activemodel (= 3.2.16)
|
28
|
+
activesupport (= 3.2.16)
|
29
29
|
arel (~> 3.0.2)
|
30
30
|
tzinfo (~> 0.3.29)
|
31
|
-
activeresource (3.2.
|
32
|
-
activemodel (= 3.2.
|
33
|
-
activesupport (= 3.2.
|
34
|
-
activesupport (3.2.
|
35
|
-
i18n (~> 0.6)
|
31
|
+
activeresource (3.2.16)
|
32
|
+
activemodel (= 3.2.16)
|
33
|
+
activesupport (= 3.2.16)
|
34
|
+
activesupport (3.2.16)
|
35
|
+
i18n (~> 0.6, >= 0.6.4)
|
36
36
|
multi_json (~> 1.0)
|
37
|
-
appraisal (0.
|
37
|
+
appraisal (1.0.0.beta2)
|
38
38
|
bundler
|
39
39
|
rake
|
40
|
-
|
41
|
-
|
40
|
+
thor (>= 0.14.0)
|
41
|
+
arel (3.0.3)
|
42
|
+
aruba (0.5.3)
|
42
43
|
childprocess (~> 0.3.6)
|
43
44
|
cucumber (>= 1.1.1)
|
44
45
|
rspec-expectations (>= 2.7.0)
|
45
|
-
bourne (1.
|
46
|
-
mocha (
|
46
|
+
bourne (1.5.0)
|
47
|
+
mocha (>= 0.13.2, < 0.15)
|
47
48
|
builder (3.0.4)
|
48
|
-
childprocess (0.3.
|
49
|
-
ffi (~> 1.0, >= 1.0.
|
50
|
-
|
49
|
+
childprocess (0.3.9)
|
50
|
+
ffi (~> 1.0, >= 1.0.11)
|
51
|
+
coderay (1.1.0)
|
52
|
+
cucumber (1.3.10)
|
51
53
|
builder (>= 2.1.2)
|
52
54
|
diff-lcs (>= 1.1.3)
|
53
|
-
gherkin (~> 2.
|
54
|
-
|
55
|
-
|
55
|
+
gherkin (~> 2.12)
|
56
|
+
multi_json (>= 1.7.5, < 2.0)
|
57
|
+
multi_test (>= 0.0.2)
|
58
|
+
diff-lcs (1.2.5)
|
56
59
|
erubis (2.7.0)
|
57
|
-
ffi (1.
|
58
|
-
gherkin (2.
|
59
|
-
|
60
|
-
hike (1.2.
|
61
|
-
i18n (0.6.
|
60
|
+
ffi (1.9.3)
|
61
|
+
gherkin (2.12.2)
|
62
|
+
multi_json (~> 1.3)
|
63
|
+
hike (1.2.3)
|
64
|
+
i18n (0.6.9)
|
62
65
|
journey (1.0.4)
|
63
|
-
json (1.
|
64
|
-
mail (2.
|
65
|
-
i18n (>= 0.4.0)
|
66
|
+
json (1.8.1)
|
67
|
+
mail (2.5.4)
|
66
68
|
mime-types (~> 1.16)
|
67
69
|
treetop (~> 1.4.8)
|
68
70
|
metaclass (0.0.1)
|
69
|
-
|
70
|
-
|
71
|
+
method_source (0.8.2)
|
72
|
+
mime-types (1.25.1)
|
73
|
+
mocha (0.14.0)
|
71
74
|
metaclass (~> 0.0.1)
|
72
|
-
multi_json (1.
|
75
|
+
multi_json (1.8.4)
|
76
|
+
multi_test (0.0.3)
|
73
77
|
polyglot (0.3.3)
|
78
|
+
pry (0.9.12.6)
|
79
|
+
coderay (~> 1.0)
|
80
|
+
method_source (~> 0.8)
|
81
|
+
slop (~> 3.4)
|
74
82
|
rack (1.4.5)
|
75
83
|
rack-cache (1.2)
|
76
84
|
rack (>= 0.4)
|
@@ -78,48 +86,50 @@ GEM
|
|
78
86
|
rack
|
79
87
|
rack-test (0.6.2)
|
80
88
|
rack (>= 1.0)
|
81
|
-
rails (3.2.
|
82
|
-
actionmailer (= 3.2.
|
83
|
-
actionpack (= 3.2.
|
84
|
-
activerecord (= 3.2.
|
85
|
-
activeresource (= 3.2.
|
86
|
-
activesupport (= 3.2.
|
89
|
+
rails (3.2.16)
|
90
|
+
actionmailer (= 3.2.16)
|
91
|
+
actionpack (= 3.2.16)
|
92
|
+
activerecord (= 3.2.16)
|
93
|
+
activeresource (= 3.2.16)
|
94
|
+
activesupport (= 3.2.16)
|
87
95
|
bundler (~> 1.0)
|
88
|
-
railties (= 3.2.
|
89
|
-
railties (3.2.
|
90
|
-
actionpack (= 3.2.
|
91
|
-
activesupport (= 3.2.
|
96
|
+
railties (= 3.2.16)
|
97
|
+
railties (3.2.16)
|
98
|
+
actionpack (= 3.2.16)
|
99
|
+
activesupport (= 3.2.16)
|
92
100
|
rack-ssl (~> 1.3.2)
|
93
101
|
rake (>= 0.8.7)
|
94
102
|
rdoc (~> 3.4)
|
95
103
|
thor (>= 0.14.6, < 2.0)
|
96
|
-
rake (10.
|
104
|
+
rake (10.1.1)
|
97
105
|
rdoc (3.12.2)
|
98
106
|
json (~> 1.4)
|
99
|
-
rspec-core (2.
|
100
|
-
rspec-expectations (2.
|
107
|
+
rspec-core (2.14.7)
|
108
|
+
rspec-expectations (2.14.4)
|
101
109
|
diff-lcs (>= 1.1.3, < 2.0)
|
102
|
-
rspec-mocks (2.
|
103
|
-
rspec-rails (2.
|
110
|
+
rspec-mocks (2.14.4)
|
111
|
+
rspec-rails (2.14.1)
|
104
112
|
actionpack (>= 3.0)
|
113
|
+
activemodel (>= 3.0)
|
105
114
|
activesupport (>= 3.0)
|
106
115
|
railties (>= 3.0)
|
107
|
-
rspec-core (~> 2.
|
108
|
-
rspec-expectations (~> 2.
|
109
|
-
rspec-mocks (~> 2.
|
110
|
-
shoulda-context (1.
|
116
|
+
rspec-core (~> 2.14.0)
|
117
|
+
rspec-expectations (~> 2.14.0)
|
118
|
+
rspec-mocks (~> 2.14.0)
|
119
|
+
shoulda-context (1.2.0)
|
120
|
+
slop (3.4.7)
|
111
121
|
sprockets (2.2.2)
|
112
122
|
hike (~> 1.2)
|
113
123
|
multi_json (~> 1.0)
|
114
124
|
rack (~> 1.0)
|
115
125
|
tilt (~> 1.1, != 1.3.0)
|
116
|
-
sqlite3 (1.3.
|
117
|
-
thor (0.
|
118
|
-
tilt (1.
|
119
|
-
treetop (1.4.
|
126
|
+
sqlite3 (1.3.8)
|
127
|
+
thor (0.18.1)
|
128
|
+
tilt (1.4.1)
|
129
|
+
treetop (1.4.15)
|
120
130
|
polyglot
|
121
131
|
polyglot (>= 0.3.1)
|
122
|
-
tzinfo (0.3.
|
132
|
+
tzinfo (0.3.38)
|
123
133
|
|
124
134
|
PLATFORMS
|
125
135
|
ruby
|
@@ -127,17 +137,18 @@ PLATFORMS
|
|
127
137
|
DEPENDENCIES
|
128
138
|
activerecord-jdbc-adapter
|
129
139
|
activerecord-jdbcsqlite3-adapter
|
130
|
-
appraisal (~> 0.
|
140
|
+
appraisal (~> 1.0.0.beta2)
|
131
141
|
aruba
|
132
142
|
bourne (~> 1.3)
|
133
143
|
bundler (~> 1.1)
|
134
144
|
cucumber (~> 1.1)
|
135
145
|
jdbc-sqlite3
|
136
146
|
jruby-openssl
|
147
|
+
pry
|
137
148
|
rails (~> 3.0)
|
138
149
|
rake (>= 0.9.2)
|
139
150
|
rspec-rails (>= 2.13.1, < 3)
|
140
|
-
shoulda-context (~> 1.
|
151
|
+
shoulda-context (~> 1.2.0)
|
141
152
|
shoulda-matchers!
|
142
153
|
sqlite3
|
143
154
|
therubyrhino
|
data/MIT-LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -1,4 +1,66 @@
|
|
1
|
-
#
|
1
|
+
# 2.6.0
|
2
|
+
|
3
|
+
* The boolean argument to `have_db_index`'s `unique` option is now optional, for
|
4
|
+
consistency with other matchers.
|
5
|
+
|
6
|
+
* Association matchers now test that the model being referred to (either
|
7
|
+
implicitly or explicitly, using `:class_name`) actually exists.
|
8
|
+
|
9
|
+
* Add ability to test `:autosave` option on associations.
|
10
|
+
|
11
|
+
* Fix `validate_uniqueness_of(...).allow_nil` so that it can be used against an
|
12
|
+
non-password attribute which is in a model that `has_secure_password`. Doing
|
13
|
+
so previously would result in a "Password digest missing on new record" error.
|
14
|
+
|
15
|
+
* Fix description for `validate_numericality_of` so that if the matcher fails,
|
16
|
+
the error message reported does not say the matcher accepts integer values if
|
17
|
+
you didn't specify that.
|
18
|
+
|
19
|
+
* Fix `ensure_inclusion_of` so that you can use it against a boolean column
|
20
|
+
(and pass boolean values to `in_array`). There are two caveats:
|
21
|
+
|
22
|
+
* You should not test that your attribute allows both true and false
|
23
|
+
(`.in_array([true, false]`); there's no way to test that it doesn't accept
|
24
|
+
anything other than that.
|
25
|
+
* You cannot test that your attribute allows nil (`.in_array([nil])`) if
|
26
|
+
the column does not allow null values.
|
27
|
+
|
28
|
+
* Change `validate_uniqueness_of(...)` so that it provides default values for
|
29
|
+
non-nullable attributes.
|
30
|
+
|
31
|
+
* Running `rake` now installs Appraisals before running the test suite.
|
32
|
+
(Additionally, we now manage Appraisals using the `appraisal` executable in
|
33
|
+
Appraisal 1.0.0.)
|
34
|
+
|
35
|
+
* Add `allow_nil` option to `validate_numericality_of` so that you can validate
|
36
|
+
that numeric values are validated only if a value is supplied.
|
37
|
+
|
38
|
+
* Fix `validate_numericality_of` so that test fails when the value with
|
39
|
+
`greater_than`, `greater_than_or_equal_to`, `less_than`, `less_than_or_equal_
|
40
|
+
to` or `equal_to` is not appropriate.
|
41
|
+
|
42
|
+
* Change `validate_presence_of` under Rails 4 so that if you are using it with a
|
43
|
+
user whose model `has_secure_password` and whose password is set to a value,
|
44
|
+
you will be instructed to use a user whose password is blank instead. The
|
45
|
+
reason for this change is due to the fact that Rails 4's version of
|
46
|
+
`has_secure_password` defines #password= such that `nil` will be ignored,
|
47
|
+
which interferes with how `validate_presence_of` works.
|
48
|
+
|
49
|
+
* Add ability to test `belongs_to` associations defined with `:inverse_of`.
|
50
|
+
|
51
|
+
* Add back matchers that were removed in 2.0.0: `permit`, for testing strong
|
52
|
+
parameters, and `delegate_method`, for testing delegation.
|
53
|
+
|
54
|
+
* Add new matchers for testing controller filters: `before_filter`,
|
55
|
+
`after_filter`, and `around_filter` (aliased to `before_action`,
|
56
|
+
`after_action` and `around_action` for Rails 4).
|
57
|
+
|
58
|
+
* Fix `rescue_from` matcher so that it does not raise an error when testing
|
59
|
+
a method handler which has been marked as protected or private.
|
60
|
+
|
61
|
+
* Fix compatibility issues with Rails 4.1:
|
62
|
+
* `set_the_flash` and `have_and_belongs_to_many` no longer raise errors
|
63
|
+
* Minitest no longer prints warnings whenever shoulda-matchers is required
|
2
64
|
|
3
65
|
# v 2.5.0
|
4
66
|
|
data/README.md
CHANGED
@@ -8,7 +8,9 @@ complex, and error-prone.
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
### RSpec
|
12
|
+
|
13
|
+
Include the gem in your Gemfile:
|
12
14
|
|
13
15
|
```ruby
|
14
16
|
group :test do
|
@@ -16,17 +18,45 @@ group :test do
|
|
16
18
|
end
|
17
19
|
```
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
### Test::Unit
|
22
|
+
|
23
|
+
shoulda-matchers was originally a component of
|
24
|
+
[Shoulda](http://github.com/thoughtbot/shoulda) -- it's what provides the nice
|
25
|
+
`should` syntax which is demonstrated below. For this reason, include it in
|
26
|
+
your Gemfile instead:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
group :test do
|
30
|
+
gem 'shoulda'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
### Non-Rails apps
|
35
|
+
|
36
|
+
Once it is loaded, shoulda-matchers automatically includes itself into your test
|
37
|
+
framework. It will mix in the appropriate matchers for ActiveRecord,
|
38
|
+
ActiveModel, and ActionController depending on the modules that are available at
|
39
|
+
runtime. For instance, in order to use the ActiveRecord matchers, ActiveRecord
|
40
|
+
must be available beforehand.
|
24
41
|
|
25
42
|
If your application is on Rails, everything should "just work", as
|
26
43
|
shoulda-matchers will most likely be declared after Rails in your Gemfile. If
|
27
44
|
your application is on another framework such as Sinatra or Padrino, you may
|
28
45
|
have a different setup, so you will want to ensure that you are requiring
|
29
|
-
shoulda-matchers after the components of Rails you are using.
|
46
|
+
shoulda-matchers after the components of Rails you are using. For instance,
|
47
|
+
if you wanted to use and test against ActiveModel, you'd say:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
gem 'activemodel'
|
51
|
+
gem 'shoulda-matchers'
|
52
|
+
```
|
53
|
+
|
54
|
+
and not:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
gem 'shoulda-matchers'
|
58
|
+
gem 'activemodel'
|
59
|
+
```
|
30
60
|
|
31
61
|
## Usage
|
32
62
|
|
@@ -38,7 +68,7 @@ Different matchers apply to different parts of Rails:
|
|
38
68
|
|
39
69
|
### ActiveModel Matchers
|
40
70
|
|
41
|
-
*Jump to: [allow_mass_assignment_of](#allow_mass_assignment_of), [allow_value
|
71
|
+
*Jump to: [allow_mass_assignment_of](#allow_mass_assignment_of), [allow_value](#allow_value), [ensure_inclusion_of](#ensure_inclusion_of), [ensure_exclusion_of](#ensure_exclusion_of), [ensure_length_of](#ensure_length_of), [have_secure_password](#have_secure_password), [validate_absence_of](#validate_absence_of), [validate_acceptance_of](#validate_acceptance_of), [validate_confirmation_of](#validate_confirmation_of), [validate_numericality_of](#validate_numericality_of), [validate_presence_of](#validate_presence_of), [validate_uniqueness_of](#validate_uniqueness_of)*
|
42
72
|
|
43
73
|
Note that all of the examples in this section are based on an ActiveRecord
|
44
74
|
model for simplicity, but these matchers will work just as well using an
|
@@ -81,7 +111,7 @@ class UserTest < ActiveSupport::TestCase
|
|
81
111
|
end
|
82
112
|
```
|
83
113
|
|
84
|
-
#### allow_value
|
114
|
+
#### allow_value
|
85
115
|
|
86
116
|
The `allow_value` matcher tests usage of the `validates_format_of` validation.
|
87
117
|
It asserts that an attribute can be set to one or more values, succeeding if
|
@@ -105,7 +135,11 @@ describe UserProfile do
|
|
105
135
|
it { should allow_value('http://foo.com', 'http://bar.com/baz').for(:website_url) }
|
106
136
|
it { should_not allow_value('asdfjkl').for(:website_url) }
|
107
137
|
|
108
|
-
it
|
138
|
+
it do
|
139
|
+
should allow_value('2013-01-01').
|
140
|
+
for(:birthday_as_string).
|
141
|
+
on(:create)
|
142
|
+
end
|
109
143
|
|
110
144
|
it do
|
111
145
|
should allow_value('open', 'closed').
|
@@ -119,7 +153,9 @@ class UserProfileTest < ActiveSupport::TestCase
|
|
119
153
|
should allow_value('http://foo.com', 'http://bar.com/baz').for(:website_url)
|
120
154
|
should_not allow_value('asdfjkl').for(:website_url)
|
121
155
|
|
122
|
-
should allow_value(
|
156
|
+
should allow_value('2013-01-01').
|
157
|
+
for(:birthday_as_string).
|
158
|
+
on(:create)
|
123
159
|
|
124
160
|
should allow_value('open', 'closed').
|
125
161
|
for(:state).
|
@@ -139,18 +175,6 @@ describe User do
|
|
139
175
|
end
|
140
176
|
```
|
141
177
|
|
142
|
-
The `disallow_value` matcher is the exact opposite of `allow_value`. That is,
|
143
|
-
`should_not allow_value` can also be written `should disallow_value`, and
|
144
|
-
`should allow_value` can also be written `should_not disallow_value`. Because
|
145
|
-
of this, it carries the same caveat when multiple values are provided:
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
describe User do
|
149
|
-
# 'b' and 'c' will not be tested
|
150
|
-
it { should disallow_value('a', 'b', 'c').for(:website_url) }
|
151
|
-
end
|
152
|
-
```
|
153
|
-
|
154
178
|
#### ensure_inclusion_of
|
155
179
|
|
156
180
|
The `ensure_inclusion_of` matcher tests usage of the `validates_inclusion_of`
|
@@ -169,8 +193,8 @@ end
|
|
169
193
|
|
170
194
|
# RSpec
|
171
195
|
describe Issue do
|
172
|
-
it { should ensure_inclusion_of(:state).in_array(%w(open resolved unresolved))
|
173
|
-
it { should ensure_inclusion_of(:
|
196
|
+
it { should ensure_inclusion_of(:state).in_array(%w(open resolved unresolved)) }
|
197
|
+
it { should ensure_inclusion_of(:priority).in_range(1..5) }
|
174
198
|
|
175
199
|
it do
|
176
200
|
should ensure_inclusion_of(:severity).
|
@@ -182,7 +206,7 @@ end
|
|
182
206
|
# Test::Unit
|
183
207
|
class IssueTest < ActiveSupport::TestCase
|
184
208
|
should ensure_inclusion_of(:state).in_array(%w(open resolved unresolved))
|
185
|
-
should ensure_inclusion_of(:
|
209
|
+
should ensure_inclusion_of(:priority).in_range(1..5)
|
186
210
|
|
187
211
|
should ensure_inclusion_of(:severity).
|
188
212
|
in_array(%w(low medium high)).
|
@@ -259,7 +283,7 @@ describe User do
|
|
259
283
|
should ensure_length_of(:api_token).
|
260
284
|
is_at_least(10).
|
261
285
|
is_at_most(20).
|
262
|
-
|
286
|
+
with_message('Password must be in between 10 and 20 characters')
|
263
287
|
end
|
264
288
|
|
265
289
|
it do
|
@@ -281,7 +305,7 @@ class UserTest < ActiveSupport::TestCase
|
|
281
305
|
should ensure_length_of(:api_token).
|
282
306
|
is_at_least(15).
|
283
307
|
is_at_most(20).
|
284
|
-
|
308
|
+
with_message('Password must be in between 15 and 20 characters')
|
285
309
|
|
286
310
|
should ensure_length_of(:secret_key).
|
287
311
|
is_at_least(15).
|
@@ -424,6 +448,7 @@ class Person < ActiveRecord::Base
|
|
424
448
|
validates_numericality_of :birth_year, less_than_or_equal_to: 1987
|
425
449
|
validates_numericality_of :birth_day, odd: true
|
426
450
|
validates_numericality_of :birth_month, even: true
|
451
|
+
validates_numericality_of :rank, less_than_or_equal_to: 10, allow_nil: true
|
427
452
|
|
428
453
|
validates_numericality_of :number_of_dependents,
|
429
454
|
message: 'Number of dependents must be a number'
|
@@ -443,7 +468,7 @@ describe Person do
|
|
443
468
|
|
444
469
|
it do
|
445
470
|
should validate_numericality_of(:number_of_dependents).
|
446
|
-
with_message('Number of dependents must be a number'
|
471
|
+
with_message('Number of dependents must be a number')
|
447
472
|
end
|
448
473
|
end
|
449
474
|
|
@@ -506,7 +531,7 @@ end
|
|
506
531
|
# RSpec
|
507
532
|
describe Post do
|
508
533
|
it { should validate_uniqueness_of(:permalink) }
|
509
|
-
it { should validate_uniqueness_of(:slug).scoped_to(:
|
534
|
+
it { should validate_uniqueness_of(:slug).scoped_to(:user_id) }
|
510
535
|
it { should validate_uniqueness_of(:key).case_insensitive }
|
511
536
|
it { should validate_uniqueness_of(:author_id).allow_nil }
|
512
537
|
|
@@ -519,7 +544,7 @@ end
|
|
519
544
|
# Test::Unit
|
520
545
|
class PostTest < ActiveSupport::TestCase
|
521
546
|
should validate_uniqueness_of(:permalink)
|
522
|
-
should validate_uniqueness_of(:slug).scoped_to(:
|
547
|
+
should validate_uniqueness_of(:slug).scoped_to(:user_id)
|
523
548
|
should validate_uniqueness_of(:key).case_insensitive
|
524
549
|
should validate_uniqueness_of(:author_id).allow_nil
|
525
550
|
|
@@ -884,7 +909,7 @@ end
|
|
884
909
|
|
885
910
|
### ActionController Matchers
|
886
911
|
|
887
|
-
*Jump to: [filter_param](#filter_param), [redirect_to](#redirect_to), [render_template](#render_template), [render_with_layout](#render_with_layout), [rescue_from](#rescue_from), [respond_with](#respond_with), [route](#route), [set_session](#set_session), [set_the_flash](#set_the_flash)*
|
912
|
+
*Jump to: [filter_param](#filter_param), [permit](#permit), [redirect_to](#redirect_to), [render_template](#render_template), [render_with_layout](#render_with_layout), [rescue_from](#rescue_from), [respond_with](#respond_with), [route](#route), [set_session](#set_session), [set_the_flash](#set_the_flash), [use_after_filter / use_after_action](#use_after_filter--use_after_action), [use_around_filter / use_around_action](#use_around_filter--use_around_action), [use_before_filter / use_around_action](#use_before_filter--use_before_action)*
|
888
913
|
|
889
914
|
#### filter_param
|
890
915
|
|
@@ -906,6 +931,34 @@ class ApplicationControllerTest < ActionController::TestCase
|
|
906
931
|
end
|
907
932
|
```
|
908
933
|
|
934
|
+
#### permit
|
935
|
+
|
936
|
+
The `permit` matcher tests that only whitelisted parameters are permitted.
|
937
|
+
|
938
|
+
```ruby
|
939
|
+
class UserController < ActionController::Base
|
940
|
+
def create
|
941
|
+
User.create(user_params)
|
942
|
+
end
|
943
|
+
|
944
|
+
private
|
945
|
+
|
946
|
+
def user_params
|
947
|
+
params.require(:user).permit(:email)
|
948
|
+
end
|
949
|
+
end
|
950
|
+
|
951
|
+
# RSpec
|
952
|
+
describe UserController do
|
953
|
+
it { should permit(:email).for(:create) }
|
954
|
+
end
|
955
|
+
|
956
|
+
# Test::Unit
|
957
|
+
class UserControllerTest < ActionController::TestCase
|
958
|
+
should permit(:email).for(:create)
|
959
|
+
end
|
960
|
+
```
|
961
|
+
|
909
962
|
#### redirect_to
|
910
963
|
|
911
964
|
The `redirect_to` matcher tests that an action redirects to a certain location.
|
@@ -1226,6 +1279,109 @@ class PostsControllerTest < ActionController::TestCase
|
|
1226
1279
|
end
|
1227
1280
|
```
|
1228
1281
|
|
1282
|
+
#### use_after_filter / use_after_action
|
1283
|
+
|
1284
|
+
The `use_after_filter` ensures a given `after_filter` is used. This is also
|
1285
|
+
available as `use_after_action` to provide Rails 4 support.
|
1286
|
+
|
1287
|
+
```ruby
|
1288
|
+
class UserController < ActionController::Base
|
1289
|
+
after_filter :log_activity
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
# RSpec
|
1293
|
+
describe UserController do
|
1294
|
+
it { should use_after_filter(:log_activity) }
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
# Test::Unit
|
1298
|
+
class UserControllerTest < ActionController::TestCase
|
1299
|
+
should use_after_filter(:log_activity)
|
1300
|
+
end
|
1301
|
+
```
|
1302
|
+
|
1303
|
+
#### use_around_filter / use_around_action
|
1304
|
+
|
1305
|
+
The `use_around_filter` ensures a given `around_filter` is used. This is also
|
1306
|
+
available as `use_around_action` to provide Rails 4 support.
|
1307
|
+
|
1308
|
+
```ruby
|
1309
|
+
class UserController < ActionController::Base
|
1310
|
+
around_filter :log_activity
|
1311
|
+
end
|
1312
|
+
|
1313
|
+
# RSpec
|
1314
|
+
describe UserController do
|
1315
|
+
it { should use_around_filter(:log_activity) }
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
# Test::Unit
|
1319
|
+
class UserControllerTest < ActionController::TestCase
|
1320
|
+
should use_around_filter(:log_activity)
|
1321
|
+
end
|
1322
|
+
```
|
1323
|
+
|
1324
|
+
#### use_before_filter / use_before_action
|
1325
|
+
|
1326
|
+
The `use_before_filter` ensures a given `before_filter` is used. This is also
|
1327
|
+
available as `use_before_action` for Rails 4 support.
|
1328
|
+
|
1329
|
+
```ruby
|
1330
|
+
class UserController < ActionController::Base
|
1331
|
+
before_filter :authenticate_user!
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
# RSpec
|
1335
|
+
describe UserController do
|
1336
|
+
it { should use_before_filter(:authenticate_user!) }
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
# Test::Unit
|
1340
|
+
class UserControllerTest < ActionController::TestCase
|
1341
|
+
should use_before_filter(:authenticate_user!)
|
1342
|
+
end
|
1343
|
+
```
|
1344
|
+
|
1345
|
+
## Independent Matchers
|
1346
|
+
|
1347
|
+
Matchers to test non-Rails-dependent code:
|
1348
|
+
|
1349
|
+
#### delegate_method
|
1350
|
+
|
1351
|
+
```ruby
|
1352
|
+
class Human < ActiveRecord::Base
|
1353
|
+
has_one :robot
|
1354
|
+
delegate :work, to: :robot
|
1355
|
+
|
1356
|
+
# alternatively, if you are not using Rails
|
1357
|
+
def work
|
1358
|
+
robot.work
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
def protect
|
1362
|
+
robot.protect('Sarah Connor')
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
def speak
|
1366
|
+
robot.beep_boop
|
1367
|
+
end
|
1368
|
+
end
|
1369
|
+
|
1370
|
+
# RSpec
|
1371
|
+
describe Human do
|
1372
|
+
it { should delegate_method(:work).to(:robot) }
|
1373
|
+
it { should delegate_method(:protect).to(:robot).with_arguments('Sarah Connor') }
|
1374
|
+
it { should delegate_method(:beep_boop).to(:robot).as(:speak) }
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
# Test::Unit
|
1378
|
+
class HumanTest < ActiveSupport::TestCase
|
1379
|
+
should delegate_method(:work).to(:robot)
|
1380
|
+
should delegate_method(:protect).to(:robot).with_arguments('Sarah Connor')
|
1381
|
+
should delegate_method(:beep_boop).to(:robot).as(:speak)
|
1382
|
+
end
|
1383
|
+
```
|
1384
|
+
|
1229
1385
|
## Versioning
|
1230
1386
|
|
1231
1387
|
shoulda-matchers follows Semantic Versioning 2.0 as defined at
|
@@ -1238,7 +1394,7 @@ to all the [contributors][contributors].
|
|
1238
1394
|
|
1239
1395
|
## License
|
1240
1396
|
|
1241
|
-
shoulda-matchers is copyright © 2006-
|
1397
|
+
shoulda-matchers is copyright © 2006-2014 thoughtbot, inc. It is free software,
|
1242
1398
|
and may be redistributed under the terms specified in the
|
1243
1399
|
[MIT-LICENSE](MIT-LICENSE) file.
|
1244
1400
|
|