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,255 +1,255 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "CLR to CLR interactions" do
|
4
|
-
|
5
|
-
describe "when isolating CLR interfaces" do
|
6
|
-
before do
|
7
|
-
@ninja = ClrModels::Ninja.new
|
8
|
-
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should work without expectations" do
|
12
|
-
@ninja.attack ClrModels::Ninja.new, @weapon
|
13
|
-
|
14
|
-
@weapon.did_receive?(:attack).should be_successful
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should work for expectations with an argument constraint" do
|
18
|
-
ninja = ClrModels::Ninja.new
|
19
|
-
@weapon.when_receiving(:attack).with(ninja).return(5)
|
20
|
-
|
21
|
-
@ninja.attack(ninja, @weapon).should == 5
|
22
|
-
|
23
|
-
@weapon.did_receive?(:attack).with(:any).should be_successful
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
27
|
-
@weapon.when_receiving(:attack).with(ClrModels::Ninja.new).return(5)
|
28
|
-
|
29
|
-
@ninja.attack(ClrModels::Ninja.new, @weapon).should == 0
|
30
|
-
#@ninja.attack(ClrModels::Ninja.new, ClrModels::Sword.new).should == 0
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
34
|
-
ninja = ClrModels::Ninja.new
|
35
|
-
@weapon.when_receiving(:attack).with(ninja).return(5)
|
36
|
-
|
37
|
-
@ninja.attack(ninja, @weapon).should == 5
|
38
|
-
|
39
|
-
@weapon.did_receive?(:attack).with(ninja).should be_successful
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
43
|
-
ninja = ClrModels::Ninja.new
|
44
|
-
@weapon.when_receiving(:attack).with(ninja).return(5)
|
45
|
-
|
46
|
-
@ninja.attack(ninja, @weapon).should == 5
|
47
|
-
|
48
|
-
@weapon.did_receive?(:attack).with(ClrModels::Ninja.new).should_not be_successful
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should work with an expectation with any arguments" do
|
52
|
-
@weapon.when_receiving(:damage).return(5)
|
53
|
-
|
54
|
-
@ninja.is_killed_by(@weapon).should be_true
|
55
|
-
@weapon.did_receive?(:damage).should be_successful
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should work with an expectation getting different method call result" do
|
59
|
-
@weapon.when_receiving(:damage).return(2)
|
60
|
-
|
61
|
-
@ninja.is_killed_by(@weapon).should be_false
|
62
|
-
@weapon.did_receive?(:damage).should be_successful
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should work for an assertion on a specific argument" do
|
66
|
-
@weapon.when_receiving(:damage).return(2)
|
67
|
-
|
68
|
-
@ninja.is_killed_by(@weapon).should be_false
|
69
|
-
@weapon.did_receive?(:damage).should be_successful
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "when isolating CLR classes" do
|
75
|
-
|
76
|
-
describe "plain vanilla CLR classes" do
|
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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 "that have an indexer" do
|
160
|
-
before do
|
161
|
-
@cons = ClrModels::IndexerCaller.new
|
162
|
-
@ind = Caricature::Isolation.for(ClrModels::IndexerContained)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should work without expectations" do
|
166
|
-
@cons.call_index_on_class(@ind, "key1").should be_nil
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "when isolating CLR instances" do
|
175
|
-
|
176
|
-
before do
|
177
|
-
@weapon = ClrModels::Sword.new
|
178
|
-
@ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should work without expectations" do
|
182
|
-
result = @weapon.attack @ninja
|
183
|
-
result.should == 0
|
184
|
-
|
185
|
-
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should work for expectations with an argument constraint" do
|
189
|
-
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
190
|
-
|
191
|
-
@weapon.attack(@ninja).should == 5
|
192
|
-
|
193
|
-
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
197
|
-
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
198
|
-
|
199
|
-
@weapon.attack(ClrModels::Ninja.new).should == 6
|
200
|
-
|
201
|
-
@ninja.did_receive?(:survive_attack_with).with(@weapon).should_not be_successful
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
205
|
-
ninja = ClrModels::Ninja.new
|
206
|
-
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
207
|
-
|
208
|
-
@weapon.attack(@ninja).should == 5
|
209
|
-
|
210
|
-
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
214
|
-
ninja = ClrModels::Ninja.new
|
215
|
-
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
216
|
-
|
217
|
-
@weapon.attack(@ninja).should == 5
|
218
|
-
|
219
|
-
@ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should_not be_successful
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should work with an expectation for any arguments" do
|
223
|
-
@ninja.when_receiving(:survive_attack_with).return(5)
|
224
|
-
|
225
|
-
result = @weapon.attack @ninja
|
226
|
-
result.should == 5
|
227
|
-
|
228
|
-
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should fail for an assertion for specific arguments" do
|
232
|
-
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
233
|
-
method_should.return(5)
|
234
|
-
end
|
235
|
-
|
236
|
-
result = @weapon.attack @ninja
|
237
|
-
result.should == 5
|
238
|
-
var = @ninja.did_receive?(:survive_attack_with).with(:any)
|
239
|
-
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should allow to delegate the method call to the real instance (partial mock)" do
|
243
|
-
@ninja.when_receiving(:survive_attack_with).super_after
|
244
|
-
|
245
|
-
result = @weapon.attack @ninja
|
246
|
-
result.should == 6
|
247
|
-
|
248
|
-
@ninja.did_receive?(:survive_attack_with).should be_successful
|
249
|
-
end
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
end
|
254
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "CLR to CLR interactions" do
|
4
|
+
|
5
|
+
describe "when isolating CLR interfaces" do
|
6
|
+
before do
|
7
|
+
@ninja = ClrModels::Ninja.new
|
8
|
+
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should work without expectations" do
|
12
|
+
@ninja.attack ClrModels::Ninja.new, @weapon
|
13
|
+
|
14
|
+
@weapon.did_receive?(:attack).should be_successful
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work for expectations with an argument constraint" do
|
18
|
+
ninja = ClrModels::Ninja.new
|
19
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
20
|
+
|
21
|
+
@ninja.attack(ninja, @weapon).should == 5
|
22
|
+
|
23
|
+
@weapon.did_receive?(:attack).with(:any).should be_successful
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
27
|
+
@weapon.when_receiving(:attack).with(ClrModels::Ninja.new).return(5)
|
28
|
+
|
29
|
+
@ninja.attack(ClrModels::Ninja.new, @weapon).should == 0
|
30
|
+
#@ninja.attack(ClrModels::Ninja.new, ClrModels::Sword.new).should == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
34
|
+
ninja = ClrModels::Ninja.new
|
35
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
36
|
+
|
37
|
+
@ninja.attack(ninja, @weapon).should == 5
|
38
|
+
|
39
|
+
@weapon.did_receive?(:attack).with(ninja).should be_successful
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
43
|
+
ninja = ClrModels::Ninja.new
|
44
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
45
|
+
|
46
|
+
@ninja.attack(ninja, @weapon).should == 5
|
47
|
+
|
48
|
+
@weapon.did_receive?(:attack).with(ClrModels::Ninja.new).should_not be_successful
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should work with an expectation with any arguments" do
|
52
|
+
@weapon.when_receiving(:damage).return(5)
|
53
|
+
|
54
|
+
@ninja.is_killed_by(@weapon).should be_true
|
55
|
+
@weapon.did_receive?(:damage).should be_successful
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should work with an expectation getting different method call result" do
|
59
|
+
@weapon.when_receiving(:damage).return(2)
|
60
|
+
|
61
|
+
@ninja.is_killed_by(@weapon).should be_false
|
62
|
+
@weapon.did_receive?(:damage).should be_successful
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should work for an assertion on a specific argument" do
|
66
|
+
@weapon.when_receiving(:damage).return(2)
|
67
|
+
|
68
|
+
@ninja.is_killed_by(@weapon).should be_false
|
69
|
+
@weapon.did_receive?(:damage).should be_successful
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "when isolating CLR classes" do
|
75
|
+
|
76
|
+
describe "plain vanilla CLR classes" do
|
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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 "that have an indexer" do
|
160
|
+
before do
|
161
|
+
@cons = ClrModels::IndexerCaller.new
|
162
|
+
@ind = Caricature::Isolation.for(ClrModels::IndexerContained)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should work without expectations" do
|
166
|
+
@cons.call_index_on_class(@ind, "key1").should be_nil
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "when isolating CLR instances" do
|
175
|
+
|
176
|
+
before do
|
177
|
+
@weapon = ClrModels::Sword.new
|
178
|
+
@ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should work without expectations" do
|
182
|
+
result = @weapon.attack @ninja
|
183
|
+
result.should == 0
|
184
|
+
|
185
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should work for expectations with an argument constraint" do
|
189
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
190
|
+
|
191
|
+
@weapon.attack(@ninja).should == 5
|
192
|
+
|
193
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
197
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
198
|
+
|
199
|
+
@weapon.attack(ClrModels::Ninja.new).should == 6
|
200
|
+
|
201
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should_not be_successful
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
205
|
+
ninja = ClrModels::Ninja.new
|
206
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
207
|
+
|
208
|
+
@weapon.attack(@ninja).should == 5
|
209
|
+
|
210
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
214
|
+
ninja = ClrModels::Ninja.new
|
215
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
216
|
+
|
217
|
+
@weapon.attack(@ninja).should == 5
|
218
|
+
|
219
|
+
@ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should_not be_successful
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should work with an expectation for any arguments" do
|
223
|
+
@ninja.when_receiving(:survive_attack_with).return(5)
|
224
|
+
|
225
|
+
result = @weapon.attack @ninja
|
226
|
+
result.should == 5
|
227
|
+
|
228
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should fail for an assertion for specific arguments" do
|
232
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
233
|
+
method_should.return(5)
|
234
|
+
end
|
235
|
+
|
236
|
+
result = @weapon.attack @ninja
|
237
|
+
result.should == 5
|
238
|
+
var = @ninja.did_receive?(:survive_attack_with).with(:any)
|
239
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should allow to delegate the method call to the real instance (partial mock)" do
|
243
|
+
@ninja.when_receiving(:survive_attack_with).super_after
|
244
|
+
|
245
|
+
result = @weapon.attack @ninja
|
246
|
+
result.should == 6
|
247
|
+
|
248
|
+
@ninja.did_receive?(:survive_attack_with).should be_successful
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
255
|
end
|