rspec 1.3.0 → 1.3.1.rc
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.
- data/History.rdoc +17 -0
- data/README.rdoc +10 -23
- data/examples/passing/shared_example_group_example.rb +0 -36
- data/examples/passing/simple_matcher_example.rb +3 -3
- data/features/interop/test_but_not_test_unit.feature +1 -1
- data/features/interop/test_case_with_should_methods.feature +1 -1
- data/geminstaller.yml +3 -2
- data/lib/spec/deprecation.rb +2 -1
- data/lib/spec/dsl/main.rb +1 -0
- data/lib/spec/example/example_group_methods.rb +6 -1
- data/lib/spec/example/subject.rb +8 -2
- data/lib/spec/matchers.rb +1 -1
- data/lib/spec/matchers/operator_matcher.rb +6 -1
- data/lib/spec/matchers/pretty.rb +2 -2
- data/lib/spec/matchers/simple_matcher.rb +2 -1
- data/lib/spec/matchers/throw_symbol.rb +2 -2
- data/lib/spec/mocks/proxy.rb +2 -0
- data/lib/spec/runner/backtrace_tweaker.rb +3 -2
- data/lib/spec/runner/configuration.rb +8 -0
- data/lib/spec/runner/options.rb +2 -1
- data/lib/spec/version.rb +2 -2
- data/spec/spec/dsl/main_spec.rb +10 -2
- data/spec/spec/example/example_group_methods_spec.rb +19 -0
- data/spec/spec/example/example_matcher_spec.rb +3 -4
- data/spec/spec/example/subject_spec.rb +7 -0
- data/spec/spec/expectations/wrap_expectation_spec.rb +2 -1
- data/spec/spec/matchers/have_spec.rb +278 -293
- data/spec/spec/matchers/match_array_spec.rb +5 -0
- data/spec/spec/matchers/simple_matcher_spec.rb +51 -44
- data/spec/spec/matchers/throw_symbol_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_496_spec.rb +2 -4
- data/spec/spec_helper.rb +1 -1
- metadata +99 -34
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "have matcher" do
|
4
|
+
|
4
5
|
def create_collection_owner_with(n)
|
5
6
|
owner = Spec::Expectations::Helper::CollectionOwner.new
|
6
7
|
(1..n).each do |number|
|
@@ -9,6 +10,7 @@ share_as :HaveSpecHelper do
|
|
9
10
|
end
|
10
11
|
owner
|
11
12
|
end
|
13
|
+
|
12
14
|
before(:each) do
|
13
15
|
if defined?(::ActiveSupport::Inflector)
|
14
16
|
@active_support_was_defined = true
|
@@ -23,200 +25,186 @@ share_as :HaveSpecHelper do
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
|
-
end
|
27
|
-
|
28
28
|
|
29
|
-
describe "should have(n).items" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
owner.should have(3).items_in_collection_with_size_method
|
36
|
-
end
|
29
|
+
describe "should have(n).items" do
|
30
|
+
it "should pass if target has a collection of items with n members" do
|
31
|
+
owner = create_collection_owner_with(3)
|
32
|
+
owner.should have(3).items_in_collection_with_length_method
|
33
|
+
owner.should have(3).items_in_collection_with_size_method
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
it "should convert :no to 0" do
|
37
|
+
owner = create_collection_owner_with(0)
|
38
|
+
owner.should have(:no).items_in_collection_with_length_method
|
39
|
+
owner.should have(:no).items_in_collection_with_size_method
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
42
|
+
it "should fail if target has a collection of items with < n members" do
|
43
|
+
owner = create_collection_owner_with(3)
|
44
|
+
lambda {
|
45
|
+
owner.should have(4).items_in_collection_with_length_method
|
46
|
+
}.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
47
|
+
lambda {
|
48
|
+
owner.should have(4).items_in_collection_with_size_method
|
49
|
+
}.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should fail if target has a collection of items with > n members" do
|
53
|
+
owner = create_collection_owner_with(3)
|
54
|
+
lambda {
|
55
|
+
owner.should have(2).items_in_collection_with_length_method
|
56
|
+
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
57
|
+
lambda {
|
58
|
+
owner.should have(2).items_in_collection_with_size_method
|
59
|
+
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
60
|
+
end
|
62
61
|
end
|
63
|
-
end
|
64
62
|
|
65
|
-
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Object.__send__ :remove_const, :ActiveSupport
|
63
|
+
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
64
|
+
it 'should pluralize the collection name' do
|
65
|
+
owner = create_collection_owner_with(1)
|
66
|
+
owner.should have(1).item
|
67
|
+
end
|
68
|
+
|
69
|
+
after(:each) do
|
70
|
+
unless @active_support_was_defined
|
71
|
+
Object.__send__ :remove_const, :ActiveSupport
|
72
|
+
end
|
76
73
|
end
|
77
74
|
end
|
78
|
-
end
|
79
75
|
|
80
|
-
describe 'should have(1).item when Inflector is defined' do
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
string.to_s + 's'
|
76
|
+
describe 'should have(1).item when Inflector is defined' do
|
77
|
+
before(:each) do
|
78
|
+
if defined?(Inflector)
|
79
|
+
@inflector_was_defined = true
|
80
|
+
else
|
81
|
+
@inflector_was_defined = false
|
82
|
+
class ::Inflector
|
83
|
+
def self.pluralize(string)
|
84
|
+
string.to_s + 's'
|
85
|
+
end
|
91
86
|
end
|
92
87
|
end
|
93
88
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
owner.should have(1).item
|
99
|
-
end
|
100
|
-
|
101
|
-
after(:each) do
|
102
|
-
unless @inflector_was_defined
|
103
|
-
Object.__send__ :remove_const, :Inflector
|
89
|
+
|
90
|
+
it 'should pluralize the collection name' do
|
91
|
+
owner = create_collection_owner_with(1)
|
92
|
+
owner.should have(1).item
|
104
93
|
end
|
105
|
-
end
|
106
|
-
end
|
107
94
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
def items
|
112
|
-
Object.new
|
95
|
+
after(:each) do
|
96
|
+
unless @inflector_was_defined
|
97
|
+
Object.__send__ :remove_const, :Inflector
|
113
98
|
end
|
114
|
-
end
|
115
|
-
lambda do
|
116
|
-
owner.should have(3).items
|
117
|
-
end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
|
99
|
+
end
|
118
100
|
end
|
119
|
-
end
|
120
101
|
|
121
|
-
describe "
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
owner.should_not have(2).items_in_collection_with_length_method
|
133
|
-
owner.should_not have(2).items_in_collection_with_size_method
|
102
|
+
describe "should have(n).items where result responds to items but returns something other than a collection" do
|
103
|
+
it "should provide a meaningful error" do
|
104
|
+
owner = Class.new do
|
105
|
+
def items
|
106
|
+
Object.new
|
107
|
+
end
|
108
|
+
end.new
|
109
|
+
lambda do
|
110
|
+
owner.should have(3).items
|
111
|
+
end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
|
112
|
+
end
|
134
113
|
end
|
135
114
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
owner.should_not have(
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
include HaveSpecHelper
|
149
|
-
|
150
|
-
it "should pass if target has a collection of items with n members" do
|
151
|
-
owner = create_collection_owner_with(3)
|
152
|
-
owner.should have_exactly(3).items_in_collection_with_length_method
|
153
|
-
owner.should have_exactly(3).items_in_collection_with_size_method
|
154
|
-
end
|
115
|
+
describe "should_not have(n).items" do
|
116
|
+
it "should pass if target has a collection of items with < n members" do
|
117
|
+
owner = create_collection_owner_with(3)
|
118
|
+
owner.should_not have(4).items_in_collection_with_length_method
|
119
|
+
owner.should_not have(4).items_in_collection_with_size_method
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should pass if target has a collection of items with > n members" do
|
123
|
+
owner = create_collection_owner_with(3)
|
124
|
+
owner.should_not have(2).items_in_collection_with_length_method
|
125
|
+
owner.should_not have(2).items_in_collection_with_size_method
|
126
|
+
end
|
155
127
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
128
|
+
it "should fail if target has a collection of items with n members" do
|
129
|
+
owner = create_collection_owner_with(3)
|
130
|
+
lambda {
|
131
|
+
owner.should_not have(3).items_in_collection_with_length_method
|
132
|
+
}.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
|
133
|
+
lambda {
|
134
|
+
owner.should_not have(3).items_in_collection_with_size_method
|
135
|
+
}.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
|
136
|
+
end
|
160
137
|
end
|
161
138
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
owner.should have_exactly(
|
166
|
-
|
167
|
-
|
168
|
-
owner.should have_exactly(4).items_in_collection_with_size_method
|
169
|
-
}.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should fail if target has a collection of items with > n members" do
|
173
|
-
owner = create_collection_owner_with(3)
|
174
|
-
lambda {
|
175
|
-
owner.should have_exactly(2).items_in_collection_with_length_method
|
176
|
-
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
177
|
-
lambda {
|
178
|
-
owner.should have_exactly(2).items_in_collection_with_size_method
|
179
|
-
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
180
|
-
end
|
181
|
-
end
|
139
|
+
describe "should have_exactly(n).items" do
|
140
|
+
it "should pass if target has a collection of items with n members" do
|
141
|
+
owner = create_collection_owner_with(3)
|
142
|
+
owner.should have_exactly(3).items_in_collection_with_length_method
|
143
|
+
owner.should have_exactly(3).items_in_collection_with_size_method
|
144
|
+
end
|
182
145
|
|
183
|
-
|
184
|
-
|
146
|
+
it "should convert :no to 0" do
|
147
|
+
owner = create_collection_owner_with(0)
|
148
|
+
owner.should have_exactly(:no).items_in_collection_with_length_method
|
149
|
+
owner.should have_exactly(:no).items_in_collection_with_size_method
|
150
|
+
end
|
185
151
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
152
|
+
it "should fail if target has a collection of items with < n members" do
|
153
|
+
owner = create_collection_owner_with(3)
|
154
|
+
lambda {
|
155
|
+
owner.should have_exactly(4).items_in_collection_with_length_method
|
156
|
+
}.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
157
|
+
lambda {
|
158
|
+
owner.should have_exactly(4).items_in_collection_with_size_method
|
159
|
+
}.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should fail if target has a collection of items with > n members" do
|
163
|
+
owner = create_collection_owner_with(3)
|
164
|
+
lambda {
|
165
|
+
owner.should have_exactly(2).items_in_collection_with_length_method
|
166
|
+
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
167
|
+
lambda {
|
168
|
+
owner.should have_exactly(2).items_in_collection_with_size_method
|
169
|
+
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
170
|
+
end
|
196
171
|
end
|
197
172
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
owner.should have_at_least(
|
202
|
-
|
203
|
-
|
204
|
-
owner.should have_at_least(4).items_in_collection_with_size_method
|
205
|
-
}.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should provide educational negative failure messages" do
|
209
|
-
#given
|
210
|
-
owner = create_collection_owner_with(3)
|
211
|
-
length_matcher = have_at_least(3).items_in_collection_with_length_method
|
212
|
-
size_matcher = have_at_least(3).items_in_collection_with_size_method
|
173
|
+
describe "should have_at_least(n).items" do
|
174
|
+
it "should pass if target has a collection of items with n members" do
|
175
|
+
owner = create_collection_owner_with(3)
|
176
|
+
owner.should have_at_least(3).items_in_collection_with_length_method
|
177
|
+
owner.should have_at_least(3).items_in_collection_with_size_method
|
178
|
+
end
|
213
179
|
|
214
|
-
|
215
|
-
|
216
|
-
|
180
|
+
it "should pass if target has a collection of items with > n members" do
|
181
|
+
owner = create_collection_owner_with(3)
|
182
|
+
owner.should have_at_least(2).items_in_collection_with_length_method
|
183
|
+
owner.should have_at_least(2).items_in_collection_with_size_method
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should fail if target has a collection of items with < n members" do
|
187
|
+
owner = create_collection_owner_with(3)
|
188
|
+
lambda {
|
189
|
+
owner.should have_at_least(4).items_in_collection_with_length_method
|
190
|
+
}.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
|
191
|
+
lambda {
|
192
|
+
owner.should have_at_least(4).items_in_collection_with_size_method
|
193
|
+
}.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
|
194
|
+
end
|
217
195
|
|
218
|
-
|
219
|
-
|
196
|
+
it "should provide educational negative failure messages" do
|
197
|
+
#given
|
198
|
+
owner = create_collection_owner_with(3)
|
199
|
+
length_matcher = have_at_least(3).items_in_collection_with_length_method
|
200
|
+
size_matcher = have_at_least(3).items_in_collection_with_size_method
|
201
|
+
|
202
|
+
#when
|
203
|
+
length_matcher.matches?(owner)
|
204
|
+
size_matcher.matches?(owner)
|
205
|
+
|
206
|
+
#then
|
207
|
+
length_matcher.failure_message_for_should_not.should == <<-EOF
|
220
208
|
Isn't life confusing enough?
|
221
209
|
Instead of having to figure out the meaning of this:
|
222
210
|
should_not have_at_least(3).items_in_collection_with_length_method
|
@@ -224,171 +212,168 @@ We recommend that you use this instead:
|
|
224
212
|
should have_at_most(2).items_in_collection_with_length_method
|
225
213
|
EOF
|
226
214
|
|
227
|
-
|
215
|
+
size_matcher.failure_message_for_should_not.should == <<-EOF
|
228
216
|
Isn't life confusing enough?
|
229
217
|
Instead of having to figure out the meaning of this:
|
230
218
|
should_not have_at_least(3).items_in_collection_with_size_method
|
231
219
|
We recommend that you use this instead:
|
232
220
|
should have_at_most(2).items_in_collection_with_size_method
|
233
221
|
EOF
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "should have_at_most(n).items" do
|
238
|
-
include HaveSpecHelper
|
239
|
-
|
240
|
-
it "should pass if target has a collection of items with n members" do
|
241
|
-
owner = create_collection_owner_with(3)
|
242
|
-
owner.should have_at_most(3).items_in_collection_with_length_method
|
243
|
-
owner.should have_at_most(3).items_in_collection_with_size_method
|
222
|
+
end
|
244
223
|
end
|
245
224
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
owner.should have_at_most(
|
250
|
-
|
251
|
-
|
252
|
-
owner.should have_at_most(2).items_in_collection_with_size_method
|
253
|
-
}.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should pass if target has a collection of items with < n members" do
|
257
|
-
owner = create_collection_owner_with(3)
|
258
|
-
owner.should have_at_most(4).items_in_collection_with_length_method
|
259
|
-
owner.should have_at_most(4).items_in_collection_with_size_method
|
260
|
-
end
|
225
|
+
describe "should have_at_most(n).items" do
|
226
|
+
it "should pass if target has a collection of items with n members" do
|
227
|
+
owner = create_collection_owner_with(3)
|
228
|
+
owner.should have_at_most(3).items_in_collection_with_length_method
|
229
|
+
owner.should have_at_most(3).items_in_collection_with_size_method
|
230
|
+
end
|
261
231
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
232
|
+
it "should fail if target has a collection of items with > n members" do
|
233
|
+
owner = create_collection_owner_with(3)
|
234
|
+
lambda {
|
235
|
+
owner.should have_at_most(2).items_in_collection_with_length_method
|
236
|
+
}.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
|
237
|
+
lambda {
|
238
|
+
owner.should have_at_most(2).items_in_collection_with_size_method
|
239
|
+
}.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
|
240
|
+
end
|
271
241
|
|
272
|
-
|
273
|
-
|
242
|
+
it "should pass if target has a collection of items with < n members" do
|
243
|
+
owner = create_collection_owner_with(3)
|
244
|
+
owner.should have_at_most(4).items_in_collection_with_length_method
|
245
|
+
owner.should have_at_most(4).items_in_collection_with_size_method
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should provide educational negative failure messages" do
|
249
|
+
#given
|
250
|
+
owner = create_collection_owner_with(3)
|
251
|
+
length_matcher = have_at_most(3).items_in_collection_with_length_method
|
252
|
+
size_matcher = have_at_most(3).items_in_collection_with_size_method
|
253
|
+
|
254
|
+
#when
|
255
|
+
length_matcher.matches?(owner)
|
256
|
+
size_matcher.matches?(owner)
|
257
|
+
|
258
|
+
#then
|
259
|
+
length_matcher.failure_message_for_should_not.should == <<-EOF
|
274
260
|
Isn't life confusing enough?
|
275
261
|
Instead of having to figure out the meaning of this:
|
276
262
|
should_not have_at_most(3).items_in_collection_with_length_method
|
277
263
|
We recommend that you use this instead:
|
278
264
|
should have_at_least(4).items_in_collection_with_length_method
|
279
265
|
EOF
|
280
|
-
|
281
|
-
|
266
|
+
|
267
|
+
size_matcher.failure_message_for_should_not.should == <<-EOF
|
282
268
|
Isn't life confusing enough?
|
283
269
|
Instead of having to figure out the meaning of this:
|
284
270
|
should_not have_at_most(3).items_in_collection_with_size_method
|
285
271
|
We recommend that you use this instead:
|
286
272
|
should have_at_least(4).items_in_collection_with_size_method
|
287
273
|
EOF
|
274
|
+
end
|
288
275
|
end
|
289
|
-
end
|
290
276
|
|
291
|
-
describe "have(n).items(args, block)" do
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
277
|
+
describe "have(n).items(args, block)" do
|
278
|
+
it "should pass args to target" do
|
279
|
+
target = mock("target")
|
280
|
+
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
|
281
|
+
target.should have(3).items("arg1","arg2")
|
282
|
+
end
|
297
283
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
284
|
+
it "should pass block to target" do
|
285
|
+
target = mock("target")
|
286
|
+
block = lambda { 5 }
|
287
|
+
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
288
|
+
target.should have(3).items("arg1","arg2", block)
|
289
|
+
end
|
303
290
|
end
|
304
|
-
end
|
305
291
|
|
306
|
-
describe "have(n).items where target IS a collection" do
|
307
|
-
|
308
|
-
|
309
|
-
|
292
|
+
describe "have(n).items where target IS a collection" do
|
293
|
+
it "should reference the number of items IN the collection" do
|
294
|
+
[1,2,3].should have(3).items
|
295
|
+
end
|
310
296
|
|
311
|
-
|
312
|
-
|
297
|
+
it "should fail when the number of items IN the collection is not as expected" do
|
298
|
+
lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
|
299
|
+
end
|
313
300
|
end
|
314
|
-
end
|
315
301
|
|
316
|
-
describe "have(n).characters where target IS a String" do
|
317
|
-
|
318
|
-
|
319
|
-
|
302
|
+
describe "have(n).characters where target IS a String" do
|
303
|
+
it "should pass if the length is correct" do
|
304
|
+
"this string".should have(11).characters
|
305
|
+
end
|
320
306
|
|
321
|
-
|
322
|
-
|
307
|
+
it "should fail if the length is incorrect" do
|
308
|
+
lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
|
309
|
+
end
|
323
310
|
end
|
324
|
-
end
|
325
311
|
|
326
|
-
describe "have(n).things on an object which is not a collection nor contains one" do
|
327
|
-
|
328
|
-
|
312
|
+
describe "have(n).things on an object which is not a collection nor contains one" do
|
313
|
+
it "should fail" do
|
314
|
+
lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
|
315
|
+
end
|
329
316
|
end
|
330
|
-
end
|
331
317
|
|
332
|
-
describe Spec::Matchers::Have, "for a collection owner that implements #send" do
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
}.should_not raise_error
|
345
|
-
end
|
318
|
+
describe Spec::Matchers::Have, "for a collection owner that implements #send" do
|
319
|
+
before(:each) do
|
320
|
+
@collection = Object.new
|
321
|
+
def @collection.floozles; [1,2] end
|
322
|
+
def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should work in the straightforward case" do
|
326
|
+
lambda {
|
327
|
+
@collection.should have(2).floozles
|
328
|
+
}.should_not raise_error
|
329
|
+
end
|
346
330
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
331
|
+
it "should work when doing automatic pluralization" do
|
332
|
+
lambda {
|
333
|
+
@collection.should have_at_least(1).floozle
|
334
|
+
}.should_not raise_error
|
335
|
+
end
|
352
336
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
337
|
+
it "should blow up when the owner doesn't respond to that method" do
|
338
|
+
lambda {
|
339
|
+
@collection.should have(99).problems
|
340
|
+
}.should raise_error(NoMethodError, /problems/)
|
341
|
+
end
|
357
342
|
end
|
358
|
-
end
|
359
343
|
|
360
|
-
module Spec
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
describe "respond_to?" do
|
366
|
-
before :each do
|
367
|
-
@have = Have.new(:foo)
|
368
|
-
@a_method_which_have_defines = Have.instance_methods.first
|
369
|
-
@a_method_which_object_defines = Object.instance_methods.first
|
370
|
-
end
|
344
|
+
module Spec
|
345
|
+
module Matchers
|
346
|
+
describe Have do
|
347
|
+
treats_method_missing_as_private :noop => false
|
371
348
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
349
|
+
describe "respond_to?" do
|
350
|
+
before :each do
|
351
|
+
@have = Have.new(:foo)
|
352
|
+
@a_method_which_have_defines = Have.instance_methods.first
|
353
|
+
@a_method_which_object_defines = Object.instance_methods.first
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should be true for a method which Have defines" do
|
357
|
+
@have.should respond_to(@a_method_which_have_defines)
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should be true for a method that it's superclass (Object) defines" do
|
361
|
+
@have.should respond_to(@a_method_which_object_defines)
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should be false for a method which neither Object nor nor Have defines" do
|
365
|
+
@have.should_not respond_to(:foo_bar_baz)
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should be false if the owner doesn't respond to the method" do
|
369
|
+
have = Have.new(99)
|
370
|
+
have.should_not respond_to(:problems)
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should be true if the owner responds to the method" do
|
374
|
+
have = Have.new(:a_symbol)
|
375
|
+
have.should respond_to(:to_sym)
|
376
|
+
end
|
392
377
|
end
|
393
378
|
end
|
394
379
|
end
|