caricature 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,726 +0,0 @@
1
- require File.dirname(__FILE__) + "/bacon_helper"
2
-
3
- describe "Full scenarios" do
4
-
5
- describe "CLR to CLR interactions" do
6
-
7
- describe "when isolating CLR interfaces" do
8
- before do
9
- @ninja = ClrModels::Ninja.new
10
- @weapon = Caricature::Isolation.for(ClrModels::IWeapon)
11
- end
12
-
13
- it "should work without expectations" do
14
- @ninja.attack ClrModels::Ninja.new, @weapon
15
-
16
- @weapon.did_receive?(:attack).should.be.successful
17
- end
18
-
19
- it "should work for expectations with an argument constraint" do
20
- ninja = ClrModels::Ninja.new
21
- @weapon.when_receiving(:attack).with(ninja).return(5)
22
-
23
- @ninja.attack(ninja, @weapon).should.equal 5
24
-
25
- @weapon.did_receive?(:attack).with(:any).should.be.successful
26
- end
27
-
28
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
29
- @weapon.when_receiving(:attack).with(ClrModels::Ninja.new).return(5)
30
-
31
- @ninja.attack(ClrModels::Ninja.new, @weapon).should.equal 0
32
- end
33
-
34
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
35
- ninja = ClrModels::Ninja.new
36
- @weapon.when_receiving(:attack).with(ninja).return(5)
37
-
38
- @ninja.attack(ninja, @weapon).should.equal 5
39
-
40
- @weapon.did_receive?(:attack).with(ninja).should.be.successful
41
- end
42
-
43
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
44
- ninja = ClrModels::Ninja.new
45
- @weapon.when_receiving(:attack).with(ninja).return(5)
46
-
47
- @ninja.attack(ninja, @weapon).should.equal 5
48
-
49
- @weapon.did_receive?(:attack).with(ClrModels::Ninja.new).should.not.be.successful
50
- end
51
-
52
- it "should work with an expectation with any arguments" do
53
- @weapon.when_receiving(:damage).return(5)
54
-
55
- @ninja.is_killed_by(@weapon).should.be.true?
56
- @weapon.did_receive?(:damage).should.be.successful
57
- end
58
-
59
- it "should work with an expectation getting different method call result" do
60
- @weapon.when_receiving(:damage).return(2)
61
-
62
- @ninja.is_killed_by(@weapon).should.be.false?
63
- @weapon.did_receive?(:damage).should.be.successful
64
- end
65
-
66
- it "should work for an assertion on a specific argument" do
67
- @weapon.when_receiving(:damage).return(2)
68
-
69
- @ninja.is_killed_by(@weapon).should.be.false?
70
- @weapon.did_receive?(:damage).should.be.successful
71
- end
72
-
73
- end
74
-
75
- describe "when isolating CLR classes" do
76
-
77
- before do
78
- @weapon = ClrModels::Sword.new
79
- @ninja = Caricature::Isolation.for(ClrModels::Ninja)
80
- end
81
-
82
- it "should work without expectations" do
83
- result = @weapon.attack @ninja
84
- result.should.equal 0
85
-
86
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
87
- end
88
-
89
- it "should work for expectations with an argument constraint" do
90
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
91
-
92
- @weapon.attack(@ninja).should.equal 5
93
-
94
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
95
- end
96
-
97
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
98
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
99
-
100
- @weapon.attack(ClrModels::Ninja.new).should.equal 6
101
-
102
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
103
- end
104
-
105
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
106
- ninja = ClrModels::Ninja.new
107
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
108
-
109
- @weapon.attack(@ninja).should.equal 5
110
-
111
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
112
- end
113
-
114
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
115
- ninja = ClrModels::Ninja.new
116
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
117
-
118
- @weapon.attack(@ninja).should.equal 5
119
-
120
- @ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should.not.be.successful
121
- end
122
-
123
- it "should work with an expectation for any arguments" do
124
- @ninja.when_receiving(:survive_attack_with).return(5)
125
-
126
- result = @weapon.attack @ninja
127
- result.should.equal 5
128
-
129
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
130
- end
131
-
132
- it "should work with an assertion for specific arguments" do
133
- @ninja.when_receiving(:survive_attack_with) do |method_should|
134
- method_should.return(5)
135
- end
136
-
137
- result = @weapon.attack @ninja
138
- result.should.equal 5
139
-
140
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
141
- end
142
-
143
- it "should fail for an assertion with wrong arguments" do
144
- @ninja.when_receiving(:survive_attack_with) do |method_should|
145
- method_should.return(5)
146
- end
147
-
148
- result = @weapon.attack @ninja
149
- result.should.equal 5
150
-
151
- @ninja.
152
- did_receive?(:survive_attack_with).
153
- with(Caricature::Isolation.for(ClrModels::IWeapon)).
154
- should.not.be.successful
155
- end
156
-
157
- end
158
-
159
- describe "when isolating CLR instances" do
160
-
161
- before do
162
- @weapon = ClrModels::Sword.new
163
- @ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
164
- end
165
-
166
- it "should work without expectations" do
167
- result = @weapon.attack @ninja
168
- result.should.equal 0
169
-
170
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
171
- end
172
-
173
- it "should work for expectations with an argument constraint" do
174
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
175
-
176
- @weapon.attack(@ninja).should.equal 5
177
-
178
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
179
- end
180
-
181
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
182
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
183
-
184
- @weapon.attack(ClrModels::Ninja.new).should.equal 6
185
-
186
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
187
- end
188
-
189
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
190
- ninja = ClrModels::Ninja.new
191
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
192
-
193
- @weapon.attack(@ninja).should.equal 5
194
-
195
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
196
- end
197
-
198
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
199
- ninja = ClrModels::Ninja.new
200
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
201
-
202
- @weapon.attack(@ninja).should.equal 5
203
-
204
- @ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should.not.be.successful
205
- end
206
-
207
- it "should work with an expectation for any arguments" do
208
- @ninja.when_receiving(:survive_attack_with).return(5)
209
-
210
- result = @weapon.attack @ninja
211
- result.should.equal 5
212
-
213
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
214
- end
215
-
216
- it "should fail for an assertion for specific arguments" do
217
- @ninja.when_receiving(:survive_attack_with) do |method_should|
218
- method_should.return(5)
219
- end
220
-
221
- result = @weapon.attack @ninja
222
- result.should.equal 5
223
- var = @ninja.did_receive?(:survive_attack_with).with(:any)
224
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
225
- end
226
-
227
- it "should allow to delegate the method call to the real instance (partial mock)" do
228
- @ninja.when_receiving(:survive_attack_with).super_after
229
-
230
- result = @weapon.attack @ninja
231
- result.should.equal 6
232
-
233
- @ninja.did_receive?(:survive_attack_with).should.be.successful
234
- end
235
-
236
- end
237
-
238
- end
239
-
240
- describe "CLR isolations for ruby objects" do
241
-
242
- describe "when isolating CLR interfaces" do
243
- before do
244
- @soldier = Soldier.new
245
- @weapon = Caricature::Isolation.for(ClrModels::IWeapon)
246
- end
247
-
248
- it "should work without expectations" do
249
- @soldier.attack Soldier.new, @weapon
250
-
251
- @weapon.did_receive?(:attack).should.be.successful
252
- end
253
-
254
- it "should work for expectations with an argument constraint" do
255
- soldier = Soldier.new
256
- @weapon.when_receiving(:attack).with(soldier).return(5)
257
-
258
- @soldier.attack(soldier, @weapon).should.equal 5
259
-
260
- @weapon.did_receive?(:attack).with(:any).should.be.successful
261
- end
262
-
263
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
264
- @weapon.when_receiving(:attack).with(Soldier.new).return(5)
265
-
266
- @soldier.attack(Soldier.new, @weapon).should.equal 0
267
- end
268
-
269
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
270
- soldier = Soldier.new
271
- @weapon.when_receiving(:attack).with(soldier).return(5)
272
-
273
- @soldier.attack(soldier, @weapon).should.equal 5
274
-
275
- @weapon.did_receive?(:attack).with(soldier).should.be.successful
276
- end
277
-
278
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
279
- soldier = Soldier.new
280
- @weapon.when_receiving(:attack).with(soldier).return(5)
281
-
282
- @soldier.attack(soldier, @weapon).should.equal 5
283
-
284
- @weapon.did_receive?(:attack).with(Soldier.new).should.not.be.successful
285
- end
286
-
287
- it "should work with an expectation with any arguments" do
288
- @weapon.when_receiving(:damage).return(5)
289
-
290
- @soldier.is_killed_by?(@weapon).should.be.true?
291
- @weapon.did_receive?(:damage).should.be.successful
292
- end
293
-
294
- it "should work with an expectation getting different method call result" do
295
- @weapon.when_receiving(:damage).return(2)
296
-
297
- @soldier.is_killed_by?(@weapon).should.be.false?
298
- @weapon.did_receive?(:damage).should.be.successful
299
- end
300
-
301
- it "should work for an assertion on a specific argument" do
302
- @weapon.when_receiving(:damage).return(2)
303
-
304
- @soldier.is_killed_by?(@weapon).should.be.false?
305
- @weapon.did_receive?(:damage).should.be.successful
306
- end
307
-
308
- end
309
-
310
- describe "when isolating CLR classes" do
311
-
312
- before do
313
- @weapon = Dagger.new
314
- @ninja = Caricature::Isolation.for(ClrModels::Ninja)
315
- end
316
-
317
- it "should work without expectations" do
318
- result = @weapon.attack @ninja
319
- result.should.equal 0
320
-
321
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
322
- end
323
-
324
- it "should work for expectations with an argument constraint" do
325
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
326
-
327
- @weapon.attack(@ninja).should.equal 5
328
-
329
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
330
- end
331
-
332
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
333
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
334
-
335
- @weapon.attack(Soldier.new).should.equal 8
336
-
337
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
338
- end
339
-
340
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
341
- ninja = ClrModels::Ninja.new
342
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
343
-
344
- @weapon.attack(@ninja).should.equal 5
345
-
346
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
347
- end
348
-
349
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
350
- ninja = ClrModels::Ninja.new
351
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
352
-
353
- @weapon.attack(@ninja).should.equal 5
354
-
355
- @ninja.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
356
- end
357
-
358
- it "should work with an expectation for any arguments" do
359
- @ninja.when_receiving(:survive_attack_with).return(5)
360
-
361
- result = @weapon.attack @ninja
362
- result.should.equal 5
363
-
364
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
365
- end
366
-
367
- it "should work with an assertion for specific arguments" do
368
- @ninja.when_receiving(:survive_attack_with) do |method_should|
369
- method_should.return(5)
370
- end
371
-
372
- result = @weapon.attack @ninja
373
- result.should.equal 5
374
-
375
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
376
- end
377
-
378
- it "should fail for an assertion with wrong arguments" do
379
- @ninja.when_receiving(:survive_attack_with) do |method_should|
380
- method_should.return(5)
381
- end
382
-
383
- result = @weapon.attack @ninja
384
- result.should.equal 5
385
-
386
- @ninja.
387
- did_receive?(:survive_attack_with).
388
- with(Caricature::Isolation.for(ClrModels::IWeapon)).
389
- should.not.be.successful
390
- end
391
-
392
- end
393
-
394
- describe "when isolating CLR instances" do
395
-
396
- before do
397
- @weapon = Dagger.new
398
- @ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
399
- end
400
-
401
- it "should work without expectations" do
402
- result = @weapon.attack @ninja
403
- result.should.equal 0
404
-
405
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
406
- end
407
-
408
- it "should work for expectations with an argument constraint" do
409
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
410
-
411
- @weapon.attack(@ninja).should.equal 5
412
-
413
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
414
- end
415
-
416
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
417
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
418
-
419
- @weapon.attack(Soldier.new).should.equal 8
420
-
421
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
422
- end
423
-
424
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
425
- ninja = ClrModels::Ninja.new
426
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
427
-
428
- @weapon.attack(@ninja).should.equal 5
429
-
430
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
431
- end
432
-
433
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
434
- ninja = ClrModels::Ninja.new
435
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
436
-
437
- @weapon.attack(@ninja).should.equal 5
438
-
439
- @ninja.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
440
- end
441
-
442
- it "should work with an expectation for any arguments" do
443
- @ninja.when_receiving(:survive_attack_with).return(5)
444
-
445
- result = @weapon.attack @ninja
446
- result.should.equal 5
447
-
448
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
449
- end
450
-
451
- it "should fail for an assertion for specific arguments" do
452
- @ninja.when_receiving(:survive_attack_with) do |method_should|
453
- method_should.return(5)
454
- end
455
-
456
- result = @weapon.attack @ninja
457
- result.should.equal 5
458
- var = @ninja.did_receive?(:survive_attack_with).with(:any)
459
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
460
- end
461
-
462
-
463
- end
464
-
465
- end
466
-
467
- describe "Ruby to Ruby interactions" do
468
-
469
- describe "when isolating Ruby classes" do
470
-
471
- before do
472
- @dagger = Dagger.new
473
- @soldier = Caricature::Isolation.for(Soldier)
474
- end
475
-
476
- it "should work without expectations" do
477
- result = @dagger.attack @soldier
478
- result.should.equal nil
479
-
480
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
481
- end
482
-
483
- it "should work for expectations with an argument constraint" do
484
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
485
-
486
- @dagger.attack(@soldier).should.equal 5
487
-
488
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
489
- end
490
-
491
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
492
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
493
-
494
- @dagger.attack(Soldier.new).should.equal 8
495
-
496
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
497
- end
498
-
499
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
500
- soldier = Soldier.new
501
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
502
-
503
- @dagger.attack(@soldier).should.equal 5
504
-
505
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
506
- end
507
-
508
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
509
- soldier = Soldier.new
510
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
511
-
512
- @dagger.attack(@soldier).should.equal 5
513
-
514
- @soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
515
- end
516
-
517
- it "should work with an expectation for any arguments" do
518
- @soldier.when_receiving(:survive_attack_with).return(5)
519
-
520
- result = @dagger.attack @soldier
521
- result.should.equal 5
522
-
523
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
524
- end
525
-
526
- it "should work with an assertion for specific arguments" do
527
- @soldier.when_receiving(:survive_attack_with) do |method_should|
528
- method_should.return(5)
529
- end
530
-
531
- result = @dagger.attack @soldier
532
- result.should.equal 5
533
-
534
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
535
- end
536
-
537
- it "should fail for an assertion with wrong arguments" do
538
- @soldier.when_receiving(:survive_attack_with) do |method_should|
539
- method_should.return(5)
540
- end
541
-
542
- result = @dagger.attack @soldier
543
- result.should.equal 5
544
-
545
- @soldier.
546
- did_receive?(:survive_attack_with).
547
- with(Caricature::Isolation.for(Dagger)).
548
- should.not.be.successful
549
- end
550
-
551
- end
552
-
553
- describe "when isolating Ruby classes with class members" do
554
-
555
- before do
556
- @dagger = Dagger.new
557
- @soldier = Caricature::Isolation.for(SoldierWithClassMembers)
558
- end
559
-
560
- it "should work without expectations" do
561
- result = @dagger.attack @soldier
562
- result.should.equal nil
563
-
564
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
565
- end
566
-
567
- it "should work for expectations with an argument constraint" do
568
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
569
-
570
- @dagger.attack(@soldier).should.equal 5
571
-
572
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
573
- end
574
-
575
- it "should work for an expctation on a class method without an argument constraint" do
576
- @soldier.when_class_receives(:class_name).return(5)
577
-
578
- @soldier.class.class_name.should.equal 5
579
-
580
- @soldier.did_class_receive?(:class_name).should.be.successful
581
- end
582
-
583
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
584
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
585
-
586
- @dagger.attack(Soldier.new).should.equal 8
587
-
588
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
589
- end
590
-
591
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
592
- soldier = Soldier.new
593
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
594
-
595
- @dagger.attack(@soldier).should.equal 5
596
-
597
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
598
- end
599
-
600
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
601
- soldier = Soldier.new
602
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
603
-
604
- @dagger.attack(@soldier).should.equal 5
605
-
606
- @soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
607
- end
608
-
609
- it "should work with an expectation for any arguments" do
610
- @soldier.when_receiving(:survive_attack_with).return(5)
611
-
612
- result = @dagger.attack @soldier
613
- result.should.equal 5
614
-
615
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
616
- end
617
-
618
- it "should work with an assertion for specific arguments" do
619
- @soldier.when_receiving(:survive_attack_with) do |method_should|
620
- method_should.return(5)
621
- end
622
-
623
- result = @dagger.attack @soldier
624
- result.should.equal 5
625
-
626
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
627
- end
628
-
629
- it "should fail for an assertion with wrong arguments" do
630
- @soldier.when_receiving(:survive_attack_with) do |method_should|
631
- method_should.return(5)
632
- end
633
-
634
- result = @dagger.attack @soldier
635
- result.should.equal 5
636
-
637
- @soldier.
638
- did_receive?(:survive_attack_with).
639
- with(Caricature::Isolation.for(Dagger)).
640
- should.not.be.successful
641
- end
642
-
643
- end
644
-
645
- describe "when isolating Ruby instances" do
646
-
647
- before do
648
- @dagger = Dagger.new
649
- @soldier = Caricature::Isolation.for(Soldier.new)
650
- end
651
-
652
- it "should work without expectations" do
653
- result = @dagger.attack @soldier
654
- result.should.equal nil
655
-
656
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
657
- end
658
-
659
- it "should work for expectations with an argument constraint" do
660
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
661
-
662
- @dagger.attack(@soldier).should.equal 5
663
-
664
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
665
- end
666
-
667
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
668
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
669
-
670
- @dagger.attack(Soldier.new).should.equal 8
671
-
672
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
673
- end
674
-
675
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
676
- soldier = Soldier.new
677
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
678
-
679
- @dagger.attack(@soldier).should.equal 5
680
-
681
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
682
- end
683
-
684
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
685
- soldier = Soldier.new
686
- @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
687
-
688
- @dagger.attack(@soldier).should.equal 5
689
-
690
- @soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
691
- end
692
-
693
- it "should work with an expectation for any arguments" do
694
- @soldier.when_receiving(:survive_attack_with).return(5)
695
-
696
- result = @dagger.attack @soldier
697
- result.should.equal 5
698
-
699
- @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
700
- end
701
-
702
- it "should fail for an assertion for specific arguments" do
703
- @soldier.when_receiving(:survive_attack_with) do |method_should|
704
- method_should.return(5)
705
- end
706
-
707
- result = @dagger.attack @soldier
708
- result.should.equal 5
709
- var = @soldier.did_receive?(:survive_attack_with).with(:any)
710
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
711
- end
712
-
713
- it "should allow to delegate the method call to the real instance (partial mock)" do
714
- @soldier.when_receiving(:survive_attack_with).super_after
715
-
716
- result = @dagger.attack @soldier
717
- result.should.equal 8
718
-
719
- @soldier.did_receive?(:survive_attack_with).should.be.successful
720
- end
721
-
722
- end
723
-
724
- end
725
-
726
- end