rspec 1.3.0 → 1.3.1.rc

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- share_as :HaveSpecHelper do
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
- include HaveSpecHelper
31
-
32
- it "should pass if target has a collection of items with n members" do
33
- owner = create_collection_owner_with(3)
34
- owner.should have(3).items_in_collection_with_length_method
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
- it "should convert :no to 0" do
39
- owner = create_collection_owner_with(0)
40
- owner.should have(:no).items_in_collection_with_length_method
41
- owner.should have(:no).items_in_collection_with_size_method
42
- end
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
- it "should fail if target has a collection of items with < n members" do
45
- owner = create_collection_owner_with(3)
46
- lambda {
47
- owner.should have(4).items_in_collection_with_length_method
48
- }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
49
- lambda {
50
- owner.should have(4).items_in_collection_with_size_method
51
- }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
52
- end
53
-
54
- it "should fail if target has a collection of items with > n members" do
55
- owner = create_collection_owner_with(3)
56
- lambda {
57
- owner.should have(2).items_in_collection_with_length_method
58
- }.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
59
- lambda {
60
- owner.should have(2).items_in_collection_with_size_method
61
- }.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
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
- include HaveSpecHelper
67
-
68
- it 'should pluralize the collection name' do
69
- owner = create_collection_owner_with(1)
70
- owner.should have(1).item
71
- end
72
-
73
- after(:each) do
74
- unless @active_support_was_defined
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
- include HaveSpecHelper
82
-
83
- before(:each) do
84
- if defined?(Inflector)
85
- @inflector_was_defined = true
86
- else
87
- @inflector_was_defined = false
88
- class ::Inflector
89
- def self.pluralize(string)
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
- end
95
-
96
- it 'should pluralize the collection name' do
97
- owner = create_collection_owner_with(1)
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
- describe "should have(n).items where result responds to items but returns something other than a collection" do
109
- it "should provide a meaningful error" do
110
- owner = Class.new do
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.new
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 "should_not have(n).items" do
122
- include HaveSpecHelper
123
-
124
- it "should pass if target has a collection of items with < n members" do
125
- owner = create_collection_owner_with(3)
126
- owner.should_not have(4).items_in_collection_with_length_method
127
- owner.should_not have(4).items_in_collection_with_size_method
128
- end
129
-
130
- it "should pass if target has a collection of items with > n members" do
131
- owner = create_collection_owner_with(3)
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
- it "should fail if target has a collection of items with n members" do
137
- owner = create_collection_owner_with(3)
138
- lambda {
139
- owner.should_not have(3).items_in_collection_with_length_method
140
- }.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
141
- lambda {
142
- owner.should_not have(3).items_in_collection_with_size_method
143
- }.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
144
- end
145
- end
146
-
147
- describe "should have_exactly(n).items" do
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
- it "should convert :no to 0" do
157
- owner = create_collection_owner_with(0)
158
- owner.should have_exactly(:no).items_in_collection_with_length_method
159
- owner.should have_exactly(:no).items_in_collection_with_size_method
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
- 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(4).items_in_collection_with_length_method
166
- }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
167
- lambda {
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
- describe "should have_at_least(n).items" do
184
- include HaveSpecHelper
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
- it "should pass if target has a collection of items with n members" do
187
- owner = create_collection_owner_with(3)
188
- owner.should have_at_least(3).items_in_collection_with_length_method
189
- owner.should have_at_least(3).items_in_collection_with_size_method
190
- end
191
-
192
- it "should pass if target has a collection of items with > n members" do
193
- owner = create_collection_owner_with(3)
194
- owner.should have_at_least(2).items_in_collection_with_length_method
195
- owner.should have_at_least(2).items_in_collection_with_size_method
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
- it "should fail if target has a collection of items with < n members" do
199
- owner = create_collection_owner_with(3)
200
- lambda {
201
- owner.should have_at_least(4).items_in_collection_with_length_method
202
- }.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
203
- lambda {
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
- #when
215
- length_matcher.matches?(owner)
216
- size_matcher.matches?(owner)
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
- #then
219
- length_matcher.failure_message_for_should_not.should == <<-EOF
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
- size_matcher.failure_message_for_should_not.should == <<-EOF
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
- end
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
- it "should fail if target has a collection of items with > n members" do
247
- owner = create_collection_owner_with(3)
248
- lambda {
249
- owner.should have_at_most(2).items_in_collection_with_length_method
250
- }.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
251
- lambda {
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
- it "should provide educational negative failure messages" do
263
- #given
264
- owner = create_collection_owner_with(3)
265
- length_matcher = have_at_most(3).items_in_collection_with_length_method
266
- size_matcher = have_at_most(3).items_in_collection_with_size_method
267
-
268
- #when
269
- length_matcher.matches?(owner)
270
- size_matcher.matches?(owner)
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
- #then
273
- length_matcher.failure_message_for_should_not.should == <<-EOF
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
- size_matcher.failure_message_for_should_not.should == <<-EOF
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
- it "should pass args to target" do
293
- target = mock("target")
294
- target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
295
- target.should have(3).items("arg1","arg2")
296
- end
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
- it "should pass block to target" do
299
- target = mock("target")
300
- block = lambda { 5 }
301
- target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
302
- target.should have(3).items("arg1","arg2", block)
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
- it "should reference the number of items IN the collection" do
308
- [1,2,3].should have(3).items
309
- end
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
- it "should fail when the number of items IN the collection is not as expected" do
312
- lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
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
- it "should pass if the length is correct" do
318
- "this string".should have(11).characters
319
- end
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
- it "should fail if the length is incorrect" do
322
- lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
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
- it "should fail" do
328
- lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
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
- include HaveSpecHelper
334
-
335
- before(:each) do
336
- @collection = Object.new
337
- def @collection.floozles; [1,2] end
338
- def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
339
- end
340
-
341
- it "should work in the straightforward case" do
342
- lambda {
343
- @collection.should have(2).floozles
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
- it "should work when doing automatic pluralization" do
348
- lambda {
349
- @collection.should have_at_least(1).floozle
350
- }.should_not raise_error
351
- end
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
- it "should blow up when the owner doesn't respond to that method" do
354
- lambda {
355
- @collection.should have(99).problems
356
- }.should raise_error(NoMethodError, /problems/)
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
- module Matchers
362
- describe Have do
363
- treats_method_missing_as_private :noop => false
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
- it "should be true for a method which Have defines" do
373
- @have.should respond_to(@a_method_which_have_defines)
374
- end
375
-
376
- it "should be true for a method that it's superclass (Object) defines" do
377
- @have.should respond_to(@a_method_which_object_defines)
378
- end
379
-
380
- it "should be false for a method which neither Object nor nor Have defines" do
381
- @have.should_not respond_to(:foo_bar_baz)
382
- end
383
-
384
- it "should be false if the owner doesn't respond to the method" do
385
- have = Have.new(99)
386
- have.should_not respond_to(:problems)
387
- end
388
-
389
- it "should be true if the owner responds to the method" do
390
- have = Have.new(:a_symbol)
391
- have.should respond_to(:to_sym)
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