caricature 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +97 -97
- data/Rakefile +309 -310
- data/caricature.gemspec +123 -110
- data/lib/caricature/bacon/integration.rb +75 -75
- data/lib/caricature/bacon.rb +2 -2
- data/lib/caricature/clr/descriptor.rb +159 -159
- data/lib/caricature/clr/event_verification.rb +56 -56
- data/lib/caricature/clr/expectation.rb +100 -100
- data/lib/caricature/clr/isolation.rb +78 -78
- data/lib/caricature/clr/isolator.rb +252 -252
- data/lib/caricature/clr/messenger.rb +51 -49
- data/lib/caricature/clr/method_call_recorder.rb +96 -96
- data/lib/caricature/expectation.rb +1 -1
- data/lib/caricature/method_call_recorder.rb +3 -3
- data/lib/caricature/rspec/integration.rb +118 -118
- data/lib/caricature/version.rb +5 -5
- data/lib/caricature.rb +25 -25
- data/spec/bacon/integration/callback_spec.rb +156 -156
- data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
- data/spec/bacon/integration/event_spec.rb +97 -97
- data/spec/bacon/integration/indexer_spec.rb +27 -27
- data/spec/bacon/spec_helper.rb +4 -4
- data/spec/bacon/unit/descriptor_spec.rb +212 -212
- data/spec/bacon/unit/sword_spec.rb +39 -39
- data/spec/bacon/unit/verification_spec.rb +103 -103
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/fixtures/ExplodingCar.cs +56 -0
- data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
- data/spec/fixtures/ExposingWarrior.cs +58 -0
- data/spec/fixtures/IExplodingWarrior.cs +10 -0
- data/spec/fixtures/IExposing.cs +9 -0
- data/spec/fixtures/IExposingBridge.cs +9 -0
- data/spec/fixtures/IExposingWarrior.cs +8 -0
- data/spec/fixtures/IHaveAnIndexer.cs +8 -0
- data/spec/fixtures/IWarrior.cs +13 -0
- data/spec/fixtures/IWeapon.cs +9 -0
- data/spec/fixtures/IndexerCaller.cs +17 -0
- data/spec/fixtures/IndexerContained.cs +20 -0
- data/spec/fixtures/MyClassWithAStatic.cs +16 -0
- data/spec/fixtures/Ninja.cs +34 -0
- data/spec/fixtures/Samurai.cs +29 -0
- data/spec/fixtures/StaticCaller.cs +12 -0
- data/spec/fixtures/Sword.cs +16 -0
- data/spec/fixtures/SwordWithStatics.cs +19 -0
- data/spec/fixtures/clr_interaction.rb +61 -0
- data/spec/fixtures/dagger.rb +11 -0
- data/spec/fixtures/dagger_with_class_members.rb +11 -0
- data/spec/fixtures/sheath.rb +19 -0
- data/spec/fixtures/soldier.rb +29 -0
- data/spec/fixtures/soldier_with_class_members.rb +7 -0
- data/spec/fixtures/swift_cleanup_crew.rb +21 -0
- data/spec/fixtures/with_class_methods.rb +11 -0
- data/spec/{models → models.notused}/ClrModels.cs +241 -241
- data/spec/{models → models.notused}/ruby_models.rb +150 -150
- data/spec/rspec/integration/callback_spec.rb +156 -156
- data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
- data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/rspec/integration/indexer_spec.rb +27 -27
- data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
- data/spec/rspec/spec_helper.rb +12 -12
- data/spec/rspec/unit/core_ext_spec.rb +87 -87
- data/spec/rspec/unit/descriptor_spec.rb +210 -210
- data/spec/rspec/unit/event_spec.rb +16 -16
- data/spec/rspec/unit/expectation_spec.rb +300 -300
- data/spec/rspec/unit/interop_spec.rb +29 -29
- data/spec/rspec/unit/isolation_spec.rb +86 -86
- data/spec/rspec/unit/isolator_spec.rb +219 -219
- data/spec/rspec/unit/messaging_spec.rb +310 -310
- data/spec/rspec/unit/method_call_spec.rb +342 -342
- data/spec/rspec/unit/sword_spec.rb +39 -39
- data/spec/rspec/unit/verification_spec.rb +103 -103
- data/spec/spec_helper.rb +16 -15
- metadata +42 -11
@@ -1,343 +1,343 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "MethodCallRecorder" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@recorder = Caricature::MethodCallRecorder.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "when recording a call without arguments" do
|
10
|
-
|
11
|
-
before do
|
12
|
-
@recorder.record_call :my_method
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should have 1 method call" do
|
16
|
-
@recorder.method_calls[:instance].size.should == 1
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "recorded call" do
|
20
|
-
|
21
|
-
before do
|
22
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should have a method call collected" do
|
26
|
-
@mc.should_not be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should have the correct name" do
|
30
|
-
@mc.method_name.should == :my_method
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should have no arguments" do
|
34
|
-
@mc.args.should == [Caricature::ArgumentRecording.new]
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should have no block" do
|
38
|
-
@mc.block.should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have a count a 1" do
|
42
|
-
@mc.count.should == 1
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "when recording a call without arguments but with a block" do
|
50
|
-
|
51
|
-
before do
|
52
|
-
@block_content = "I'm in the block"
|
53
|
-
@recorder.record_call :my_method do
|
54
|
-
@block_content
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should have 1 method call" do
|
59
|
-
@recorder.method_calls[:instance].size.should == 1
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "recorded call" do
|
63
|
-
|
64
|
-
before do
|
65
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should have a method call collected" do
|
69
|
-
@mc.should_not be_nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should have the correct name" do
|
73
|
-
@mc.method_name.should == :my_method
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should have no arguments" do
|
77
|
-
@mc.args.should == [Caricature::ArgumentRecording.new]
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should have a block" do
|
81
|
-
@mc.args.first.block.should_not be_nil
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should have the correct block" do
|
85
|
-
@mc.args.first.block.call.should == @block_content
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should have a count a 1" do
|
89
|
-
@mc.count.should == 1
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "when recording a call 1 argument" do
|
97
|
-
|
98
|
-
before do
|
99
|
-
@recorder.record_call :my_method, :instance, nil, 1
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should have 1 method call" do
|
103
|
-
@recorder.method_calls[:instance].size.should == 1
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "recorded call" do
|
107
|
-
|
108
|
-
before do
|
109
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should have a method call collected" do
|
113
|
-
@mc.should_not be_nil
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should have the correct name" do
|
117
|
-
@mc.method_name.should == :my_method
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should have 1 argument" do
|
121
|
-
@mc.args.size.should == 1
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should have the correct argument" do
|
125
|
-
@mc.args.should == [Caricature::ArgumentRecording.new([1])]
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should have no block" do
|
129
|
-
@mc.block.should be_nil
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should have a count a 1" do
|
133
|
-
@mc.count.should == 1
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "when recording a call 2 arguments" do
|
141
|
-
|
142
|
-
before do
|
143
|
-
@recorder.record_call :my_method, :instance, nil, 1, 2
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should have 1 method call" do
|
147
|
-
@recorder.method_calls[:instance].size.should == 1
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "recorded call" do
|
151
|
-
|
152
|
-
before do
|
153
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should have a method call collected" do
|
157
|
-
@mc.should_not be_nil
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should have the correct name" do
|
161
|
-
@mc.method_name.should == :my_method
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should have 1 argument recording" do
|
165
|
-
@mc.args.size.should == 1
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should have the correct arguments" do
|
169
|
-
@mc.args.should == [Caricature::ArgumentRecording.new([1, 2])]
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should have no block" do
|
173
|
-
@mc.block.should be_nil
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should have a count a 1" do
|
177
|
-
@mc.count.should == 1
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "when recording 2 calls with no arguments" do
|
185
|
-
|
186
|
-
before do
|
187
|
-
@recorder.record_call :my_method
|
188
|
-
@recorder.record_call :my_method
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should have 1 method call" do
|
192
|
-
@recorder.method_calls[:instance].size.should == 1
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "recorded call" do
|
196
|
-
|
197
|
-
before do
|
198
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should have a method call collected" do
|
202
|
-
@mc.should_not be_nil
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should have the correct name" do
|
206
|
-
@mc.method_name.should == :my_method
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should have no arguments" do
|
210
|
-
@mc.args.should == [Caricature::ArgumentRecording.new]
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should have no block" do
|
214
|
-
@mc.block.should be_nil
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should have a count of 2" do
|
218
|
-
@mc.count.should == 2
|
219
|
-
end
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "when recording a call with a block" do
|
226
|
-
before do
|
227
|
-
@args = []
|
228
|
-
@b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
|
229
|
-
@args = args
|
230
|
-
end
|
231
|
-
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should return a block" do
|
235
|
-
@b.should_not be_nil
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should return a block that wraps a recording" do
|
239
|
-
@b.call 8, 9, 0
|
240
|
-
@recorder.method_calls[:instance][:some_method].args.first.blocks.first.args.should == [8, 9, 0]
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should call the original block" do
|
244
|
-
@b.call 8, 9, 0
|
245
|
-
@args.should == [8, 9, 0]
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "when recording 2 calls with different arguments" do
|
250
|
-
|
251
|
-
before do
|
252
|
-
@recorder.record_call :my_method
|
253
|
-
@recorder.record_call :my_method, :instance, nil, 1, 3, 4
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should have 1 method call" do
|
257
|
-
@recorder.method_calls[:instance].size.should == 1
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "recorded call" do
|
261
|
-
|
262
|
-
before do
|
263
|
-
@mc = @recorder.method_calls[:instance][:my_method]
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should have a method call collected" do
|
267
|
-
@mc.should_not be_nil
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should have the correct name" do
|
271
|
-
@mc.method_name.should == :my_method
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should have argument variations" do
|
275
|
-
@mc.has_argument_variations?.should be_true
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should have no block" do
|
279
|
-
@mc.block.should be_nil
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should have a count of 2" do
|
283
|
-
@mc.count.should == 2
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
end
|
289
|
-
|
290
|
-
describe "when asked if a certain method was called" do
|
291
|
-
|
292
|
-
before do
|
293
|
-
@recorder.record_call :my_method
|
294
|
-
@recorder.record_call :my_method, :instance, nil, 1, 3, 4
|
295
|
-
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should confirm when we don't care about the arguments" do
|
299
|
-
@recorder.was_called?(:my_method, nil, :instance, :any).should be_true
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should confirm when there are no argument variations" do
|
303
|
-
@recorder.record_call :another_method
|
304
|
-
@recorder.was_called?(:another_method, nil, :instance, :any).should be_true
|
305
|
-
end
|
306
|
-
|
307
|
-
it "should be negative when we provide the wrong arguments" do
|
308
|
-
@recorder.was_called?(:my_method, nil, :instance, 1, 2, 5).should be_false
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should be positive when we provide the correct arguments" do
|
312
|
-
@recorder.was_called?(:my_method, nil, :instance, 1, 3, 4).should be_true
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should be positive when we provide no arguments and a call had been recorded without arguments" do
|
316
|
-
@recorder.was_called?(:my_method, nil, :instance).should be_true
|
317
|
-
end
|
318
|
-
|
319
|
-
describe "with block" do
|
320
|
-
|
321
|
-
before do
|
322
|
-
@args = []
|
323
|
-
b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
|
324
|
-
@args << args
|
325
|
-
end
|
326
|
-
b.call 1, 3, 5
|
327
|
-
b.call 3, 4, 6
|
328
|
-
b.call
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should be positive when we provide any arguments" do
|
332
|
-
@recorder.was_called?(:some_method, [:any], :instance, :any).should be_true
|
333
|
-
end
|
334
|
-
|
335
|
-
it "should be positive when we provide specific arguments" do
|
336
|
-
@recorder.was_called?(:some_method, [1, 3, 5], :instance, :any).should be_true
|
337
|
-
end
|
338
|
-
|
339
|
-
end
|
340
|
-
|
341
|
-
end
|
342
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "MethodCallRecorder" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@recorder = Caricature::MethodCallRecorder.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when recording a call without arguments" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@recorder.record_call :my_method
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have 1 method call" do
|
16
|
+
@recorder.method_calls[:instance].size.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "recorded call" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a method call collected" do
|
26
|
+
@mc.should_not be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have the correct name" do
|
30
|
+
@mc.method_name.should == :my_method
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have no arguments" do
|
34
|
+
@mc.args.should == [Caricature::ArgumentRecording.new]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have no block" do
|
38
|
+
@mc.block.should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a count a 1" do
|
42
|
+
@mc.count.should == 1
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when recording a call without arguments but with a block" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
@block_content = "I'm in the block"
|
53
|
+
@recorder.record_call :my_method do
|
54
|
+
@block_content
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have 1 method call" do
|
59
|
+
@recorder.method_calls[:instance].size.should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "recorded call" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have a method call collected" do
|
69
|
+
@mc.should_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have the correct name" do
|
73
|
+
@mc.method_name.should == :my_method
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have no arguments" do
|
77
|
+
@mc.args.should == [Caricature::ArgumentRecording.new]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should have a block" do
|
81
|
+
@mc.args.first.block.should_not be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have the correct block" do
|
85
|
+
@mc.args.first.block.call.should == @block_content
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should have a count a 1" do
|
89
|
+
@mc.count.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "when recording a call 1 argument" do
|
97
|
+
|
98
|
+
before do
|
99
|
+
@recorder.record_call :my_method, :instance, nil, 1
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should have 1 method call" do
|
103
|
+
@recorder.method_calls[:instance].size.should == 1
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "recorded call" do
|
107
|
+
|
108
|
+
before do
|
109
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have a method call collected" do
|
113
|
+
@mc.should_not be_nil
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have the correct name" do
|
117
|
+
@mc.method_name.should == :my_method
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have 1 argument" do
|
121
|
+
@mc.args.size.should == 1
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should have the correct argument" do
|
125
|
+
@mc.args.should == [Caricature::ArgumentRecording.new([1])]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should have no block" do
|
129
|
+
@mc.block.should be_nil
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should have a count a 1" do
|
133
|
+
@mc.count.should == 1
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "when recording a call 2 arguments" do
|
141
|
+
|
142
|
+
before do
|
143
|
+
@recorder.record_call :my_method, :instance, nil, 1, 2
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have 1 method call" do
|
147
|
+
@recorder.method_calls[:instance].size.should == 1
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "recorded call" do
|
151
|
+
|
152
|
+
before do
|
153
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should have a method call collected" do
|
157
|
+
@mc.should_not be_nil
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should have the correct name" do
|
161
|
+
@mc.method_name.should == :my_method
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should have 1 argument recording" do
|
165
|
+
@mc.args.size.should == 1
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should have the correct arguments" do
|
169
|
+
@mc.args.should == [Caricature::ArgumentRecording.new([1, 2])]
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should have no block" do
|
173
|
+
@mc.block.should be_nil
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should have a count a 1" do
|
177
|
+
@mc.count.should == 1
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "when recording 2 calls with no arguments" do
|
185
|
+
|
186
|
+
before do
|
187
|
+
@recorder.record_call :my_method
|
188
|
+
@recorder.record_call :my_method
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should have 1 method call" do
|
192
|
+
@recorder.method_calls[:instance].size.should == 1
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "recorded call" do
|
196
|
+
|
197
|
+
before do
|
198
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should have a method call collected" do
|
202
|
+
@mc.should_not be_nil
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should have the correct name" do
|
206
|
+
@mc.method_name.should == :my_method
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should have no arguments" do
|
210
|
+
@mc.args.should == [Caricature::ArgumentRecording.new]
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should have no block" do
|
214
|
+
@mc.block.should be_nil
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should have a count of 2" do
|
218
|
+
@mc.count.should == 2
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "when recording a call with a block" do
|
226
|
+
before do
|
227
|
+
@args = []
|
228
|
+
@b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
|
229
|
+
@args = args
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should return a block" do
|
235
|
+
@b.should_not be_nil
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should return a block that wraps a recording" do
|
239
|
+
@b.call 8, 9, 0
|
240
|
+
@recorder.method_calls[:instance][:some_method].args.first.blocks.first.args.should == [8, 9, 0]
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should call the original block" do
|
244
|
+
@b.call 8, 9, 0
|
245
|
+
@args.should == [8, 9, 0]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "when recording 2 calls with different arguments" do
|
250
|
+
|
251
|
+
before do
|
252
|
+
@recorder.record_call :my_method
|
253
|
+
@recorder.record_call :my_method, :instance, nil, 1, 3, 4
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should have 1 method call" do
|
257
|
+
@recorder.method_calls[:instance].size.should == 1
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "recorded call" do
|
261
|
+
|
262
|
+
before do
|
263
|
+
@mc = @recorder.method_calls[:instance][:my_method]
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should have a method call collected" do
|
267
|
+
@mc.should_not be_nil
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should have the correct name" do
|
271
|
+
@mc.method_name.should == :my_method
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should have argument variations" do
|
275
|
+
@mc.has_argument_variations?.should be_true
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should have no block" do
|
279
|
+
@mc.block.should be_nil
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should have a count of 2" do
|
283
|
+
@mc.count.should == 2
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
describe "when asked if a certain method was called" do
|
291
|
+
|
292
|
+
before do
|
293
|
+
@recorder.record_call :my_method
|
294
|
+
@recorder.record_call :my_method, :instance, nil, 1, 3, 4
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should confirm when we don't care about the arguments" do
|
299
|
+
@recorder.was_called?(:my_method, nil, :instance, :any).should be_true
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should confirm when there are no argument variations" do
|
303
|
+
@recorder.record_call :another_method
|
304
|
+
@recorder.was_called?(:another_method, nil, :instance, :any).should be_true
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should be negative when we provide the wrong arguments" do
|
308
|
+
@recorder.was_called?(:my_method, nil, :instance, 1, 2, 5).should be_false
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should be positive when we provide the correct arguments" do
|
312
|
+
@recorder.was_called?(:my_method, nil, :instance, 1, 3, 4).should be_true
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should be positive when we provide no arguments and a call had been recorded without arguments" do
|
316
|
+
@recorder.was_called?(:my_method, nil, :instance).should be_true
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "with block" do
|
320
|
+
|
321
|
+
before do
|
322
|
+
@args = []
|
323
|
+
b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
|
324
|
+
@args << args
|
325
|
+
end
|
326
|
+
b.call 1, 3, 5
|
327
|
+
b.call 3, 4, 6
|
328
|
+
b.call
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should be positive when we provide any arguments" do
|
332
|
+
@recorder.was_called?(:some_method, [:any], :instance, :any).should be_true
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should be positive when we provide specific arguments" do
|
336
|
+
@recorder.was_called?(:some_method, [1, 3, 5], :instance, :any).should be_true
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
343
|
end
|