shoulda-matchers 1.5.6 → 2.0.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 +15 -0
- data/Gemfile.lock +2 -2
- data/NEWS.md +12 -0
- data/README.md +0 -11
- data/features/rails_integration.feature +6 -8
- data/gemfiles/3.0.gemfile.lock +2 -2
- data/gemfiles/3.1.gemfile.lock +2 -2
- data/gemfiles/3.2.gemfile.lock +2 -2
- data/lib/shoulda/matchers/action_controller.rb +0 -4
- data/lib/shoulda/matchers/active_model.rb +0 -2
- data/lib/shoulda/matchers/active_record.rb +0 -1
- data/lib/shoulda/matchers/integrations/rspec.rb +0 -8
- data/lib/shoulda/matchers/integrations/test_unit.rb +0 -23
- data/lib/shoulda/matchers/version.rb +1 -1
- data/shoulda-matchers.gemspec +1 -1
- data/spec/spec_helper.rb +0 -2
- data/spec/support/controller_builder.rb +0 -24
- metadata +19 -70
- data/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +0 -130
- data/lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb +0 -83
- data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +0 -121
- data/lib/shoulda/matchers/action_mailer.rb +0 -22
- data/lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb +0 -260
- data/lib/shoulda/matchers/active_model/validate_format_of_matcher.rb +0 -108
- data/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +0 -111
- data/lib/shoulda/matchers/independent.rb +0 -9
- data/lib/shoulda/matchers/independent/delegate_matcher.rb +0 -134
- data/spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb +0 -66
- data/spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb +0 -31
- data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -142
- data/spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb +0 -324
- data/spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb +0 -75
- data/spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb +0 -45
- data/spec/shoulda/matchers/independent/delegate_matcher_spec.rb +0 -204
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveModel::ValidateFormatOfMatcher do
|
4
|
-
context 'a model with a format validation' do
|
5
|
-
it 'accepts when format matches ' do
|
6
|
-
validating_format(:with => /^\d{5}$/).should matcher.with('12345')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'rejects blank with should_not' do
|
10
|
-
validating_format(:with => /^\d{5}$/).should_not matcher.with(' ')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'rejects blank with not_with' do
|
14
|
-
validating_format(:with => /^\d{5}$/).should matcher.not_with(' ')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'rejects nil' do
|
18
|
-
validating_format(:with => /^\d{5}$/).should_not matcher.with(nil)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'rejects a non-matching format with should_not' do
|
22
|
-
validating_format(:with => /^\d{5}$/).should_not matcher.with('1234a')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'rejects a non-matching format with not_with' do
|
26
|
-
validating_format(:with => /^\d{5}$/).should matcher.not_with('1234a')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'raises an error if you try to call both with and not_with' do
|
30
|
-
expect {
|
31
|
-
validate_format_of(:attr).not_with('123456').with('12345')
|
32
|
-
}.to raise_error(RuntimeError)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when allow_blank or allow_nil are set' do
|
37
|
-
it 'is valid when attr is nil' do
|
38
|
-
validating_format(:with => /abc/, :allow_nil => true).
|
39
|
-
should matcher.with(nil)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'is valid when attr is blank' do
|
43
|
-
validating_format(:with => /abc/, :allow_blank => true).
|
44
|
-
should matcher.with(' ')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context '#allow_blank' do
|
49
|
-
it 'accepts when allow_blank matches' do
|
50
|
-
validating_format(:with => /abc/, :allow_blank => true).
|
51
|
-
should matcher.allow_blank
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'rejects when allow_blank does not match' do
|
55
|
-
validating_format(:with => /abc/, :allow_blank => false).
|
56
|
-
should_not matcher.allow_blank
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context '#allow_nil' do
|
61
|
-
it 'accepts when allow_nil matches' do
|
62
|
-
validating_format(:with => /abc/, :allow_nil => true).
|
63
|
-
should matcher.allow_nil
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'rejects when allow_nil does not match' do
|
67
|
-
validating_format(:with => /abc/, :allow_nil => false).
|
68
|
-
should_not matcher.allow_nil
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def matcher
|
73
|
-
validate_format_of(:attr)
|
74
|
-
end
|
75
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActiveRecord::QueryTheDatabaseMatcher do
|
4
|
-
before do
|
5
|
-
@parent = define_model :litter do
|
6
|
-
has_many :kittens
|
7
|
-
end
|
8
|
-
@child = define_model :kitten, :litter_id => :integer do
|
9
|
-
belongs_to :litter
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'accepts the correct number of queries when there is a single query' do
|
14
|
-
@parent.should query_the_database(1.times).when_calling(:count)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'accepts any number of queries when no number is specified' do
|
18
|
-
@parent.should query_the_database.when_calling(:count)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'rejects any number of queries when no number is specified' do
|
22
|
-
@parent.should_not query_the_database.when_calling(:to_s)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'accepts the correct number of queries when there are two queries' do
|
26
|
-
nonsense = lambda do
|
27
|
-
@parent.create.kittens.create
|
28
|
-
end
|
29
|
-
nonsense.should query_the_database(2.times).when_calling(:call)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'rejects the wrong number of queries' do
|
33
|
-
@parent.should_not query_the_database(10.times).when_calling(:count)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'accepts fewer than the specified maximum' do
|
37
|
-
@parent.should query_the_database(5.times).or_less.when_calling(:count)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'passes arguments to the method to examine' do
|
41
|
-
model = stub('Model', :count => nil)
|
42
|
-
model.should_not query_the_database.when_calling(:count).with('arguments')
|
43
|
-
model.should have_received(:count).with('arguments')
|
44
|
-
end
|
45
|
-
end
|
@@ -1,204 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::Independent::DelegateMatcher do
|
4
|
-
context '#description' do
|
5
|
-
context 'by default' do
|
6
|
-
it 'states that it should delegate method to the right object' do
|
7
|
-
matcher = delegate_method(:method_name).to(:target)
|
8
|
-
|
9
|
-
matcher.description.should == 'delegate method #method_name to :target'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'with #as chain' do
|
14
|
-
it 'states that it should delegate method to the right object and method' do
|
15
|
-
matcher = delegate_method(:method_name).to(:target).as(:alternate)
|
16
|
-
|
17
|
-
matcher.description.should == 'delegate method #method_name to :target as #alternate'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with #with_argument chain' do
|
22
|
-
it 'states that it should delegate method to the right object with right argument' do
|
23
|
-
matcher = delegate_method(:method_name).to(:target).with_arguments(:foo, :bar => [1, 2])
|
24
|
-
|
25
|
-
matcher.description.should ==
|
26
|
-
'delegate method #method_name to :target with arguments: [:foo, {:bar=>[1, 2]}]'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'supports chaining on #to' do
|
32
|
-
matcher = delegate_method(:method)
|
33
|
-
|
34
|
-
matcher.to(:another_method).should == matcher
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'supports chaining on #with_arguments' do
|
38
|
-
matcher = delegate_method(:method)
|
39
|
-
|
40
|
-
matcher.with_arguments(1, 2, 3).should == matcher
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'supports chaining on #as' do
|
44
|
-
matcher = delegate_method(:method)
|
45
|
-
|
46
|
-
matcher.as(:some_other_method).should == matcher
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'raises an error if no delegation target is defined' do
|
50
|
-
expect { Object.new.should delegate_method(:name) }.
|
51
|
-
to raise_exception described_class::TargetNotDefinedError
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'raises an error if called with #should_not' do
|
55
|
-
expect { Object.new.should_not delegate_method(:name).to(:anyone) }.
|
56
|
-
to raise_exception described_class::InvalidDelegateMatcher
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'given a method that does not delegate' do
|
60
|
-
before do
|
61
|
-
define_class(:post_office) do
|
62
|
-
def deliver_mail
|
63
|
-
:delivered
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'rejects' do
|
69
|
-
post_office = PostOffice.new
|
70
|
-
matcher = delegate_method(:deliver_mail).to(:mailman)
|
71
|
-
|
72
|
-
matcher.matches?(post_office).should be_false
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'has a failure message that indicates which method should have been delegated' do
|
76
|
-
post_office = PostOffice.new
|
77
|
-
matcher = delegate_method(:deliver_mail).to(:mailman)
|
78
|
-
|
79
|
-
matcher.matches?(post_office)
|
80
|
-
|
81
|
-
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman'
|
82
|
-
matcher.failure_message_for_should.should == message
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'uses the proper syntax for class methods in errors' do
|
86
|
-
matcher = delegate_method(:deliver_mail).to(:mailman)
|
87
|
-
|
88
|
-
matcher.matches?(PostOffice)
|
89
|
-
|
90
|
-
message = 'Expected PostOffice.deliver_mail to delegate to PostOffice.mailman'
|
91
|
-
matcher.failure_message_for_should.should == message
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'given a method that delegates properly' do
|
96
|
-
it 'accepts' do
|
97
|
-
define_class(:mailman)
|
98
|
-
define_class(:post_office) do
|
99
|
-
def deliver_mail
|
100
|
-
mailman.deliver_mail
|
101
|
-
end
|
102
|
-
|
103
|
-
def mailman
|
104
|
-
Mailman.new
|
105
|
-
end
|
106
|
-
end.new.should delegate_method(:deliver_mail).to(:mailman)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'given a method that delegates properly with certain arguments' do
|
111
|
-
before do
|
112
|
-
define_class(:mailman)
|
113
|
-
define_class(:post_office) do
|
114
|
-
def deliver_mail
|
115
|
-
mailman.deliver_mail('221B Baker St.', :hastily => true)
|
116
|
-
end
|
117
|
-
|
118
|
-
def mailman
|
119
|
-
Mailman.new
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'when given the correct arguments' do
|
125
|
-
it 'accepts' do
|
126
|
-
PostOffice.new.should delegate_method(:deliver_mail).
|
127
|
-
to(:mailman).with_arguments('221B Baker St.', :hastily => true)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'when not given the correct arguments' do
|
132
|
-
it 'rejects' do
|
133
|
-
post_office = PostOffice.new
|
134
|
-
matcher = delegate_method(:deliver_mail).to(:mailman).
|
135
|
-
with_arguments('123 Nowhere Ln.')
|
136
|
-
matcher.matches?(post_office).should be_false
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'has a failure message that indicates which arguments were expected' do
|
140
|
-
post_office = PostOffice.new
|
141
|
-
matcher = delegate_method(:deliver_mail).to(:mailman).with_arguments('123 Nowhere Ln.')
|
142
|
-
|
143
|
-
matcher.matches?(post_office)
|
144
|
-
|
145
|
-
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman with arguments: ["123 Nowhere Ln."]'
|
146
|
-
matcher.failure_message_for_should.should == message
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
context 'given a method that delegates properly to a method of a different name' do
|
152
|
-
before do
|
153
|
-
define_class(:mailman)
|
154
|
-
define_class(:post_office) do
|
155
|
-
def deliver_mail
|
156
|
-
mailman.deliver_mail_and_avoid_dogs
|
157
|
-
end
|
158
|
-
|
159
|
-
def mailman
|
160
|
-
Mailman.new
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'when given the correct method name' do
|
166
|
-
it 'accepts' do
|
167
|
-
PostOffice.new.
|
168
|
-
should delegate_method(:deliver_mail).to(:mailman).as(:deliver_mail_and_avoid_dogs)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when given an incorrect method name' do
|
173
|
-
it 'rejects' do
|
174
|
-
post_office = PostOffice.new
|
175
|
-
matcher = delegate_method(:deliver_mail).to(:mailman).as(:watch_tv)
|
176
|
-
matcher.matches?(post_office).should be_false
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'has a failure message that indicates which method was expected' do
|
180
|
-
post_office = PostOffice.new
|
181
|
-
matcher = delegate_method(:deliver_mail).to(:mailman).as(:watch_tv)
|
182
|
-
|
183
|
-
matcher.matches?(post_office)
|
184
|
-
|
185
|
-
message = 'Expected PostOffice#deliver_mail to delegate to PostOffice#mailman as #watch_tv'
|
186
|
-
matcher.failure_message_for_should.should == message
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe Shoulda::Matchers::Independent::DelegateMatcher::TargetNotDefinedError do
|
193
|
-
it 'has a useful message' do
|
194
|
-
error = Shoulda::Matchers::Independent::DelegateMatcher::TargetNotDefinedError.new
|
195
|
-
error.message.should include 'Delegation needs a target'
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe Shoulda::Matchers::Independent::DelegateMatcher::InvalidDelegateMatcher do
|
200
|
-
it 'has a useful message' do
|
201
|
-
error = Shoulda::Matchers::Independent::DelegateMatcher::InvalidDelegateMatcher.new
|
202
|
-
error.message.should include 'does not support #should_not'
|
203
|
-
end
|
204
|
-
end
|