caricature 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/caricature.gemspec +30 -24
- data/lib/caricature/clr/aspnet_mvc.rb +4 -0
- data/lib/caricature/clr/descriptor.rb +37 -9
- data/lib/caricature/expectation.rb +4 -12
- data/lib/caricature/isolation.rb +0 -1
- data/spec/integration/clr_to_clr_spec.rb +254 -0
- data/spec/integration/clr_to_ruby_spec.rb +228 -0
- data/spec/integration/indexer_spec.rb +28 -0
- data/spec/integration/ruby_to_ruby_spec.rb +260 -0
- data/spec/models/ClrModels.cs +32 -0
- data/spec/{core_ext_spec.rb → unit/core_ext_spec.rb} +1 -1
- data/spec/{descriptor_spec.rb → unit/descriptor_spec.rb} +19 -1
- data/spec/{expectation_spec.rb → unit/expectation_spec.rb} +1 -1
- data/spec/{interop_spec.rb → unit/interop_spec.rb} +1 -1
- data/spec/{isolation_spec.rb → unit/isolation_spec.rb} +1 -1
- data/spec/{isolator_spec.rb → unit/isolator_spec.rb} +1 -1
- data/spec/{messaging_spec.rb → unit/messaging_spec.rb} +1 -1
- data/spec/{method_call_spec.rb → unit/method_call_spec.rb} +1 -1
- data/spec/{sword_spec.rb → unit/sword_spec.rb} +1 -1
- data/spec/{verification_spec.rb → unit/verification_spec.rb} +1 -1
- metadata +30 -24
- data/spec/integration_spec.rb +0 -726
@@ -0,0 +1,228 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../bacon_helper"
|
2
|
+
|
3
|
+
describe "CLR isolations for ruby objects" do
|
4
|
+
|
5
|
+
describe "when isolating CLR interfaces" do
|
6
|
+
before do
|
7
|
+
@soldier = Soldier.new
|
8
|
+
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should work without expectations" do
|
12
|
+
@soldier.attack Soldier.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
|
+
soldier = Soldier.new
|
19
|
+
@weapon.when_receiving(:attack).with(soldier).return(5)
|
20
|
+
|
21
|
+
@soldier.attack(soldier, @weapon).should.equal 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(Soldier.new).return(5)
|
28
|
+
|
29
|
+
@soldier.attack(Soldier.new, @weapon).should.equal 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
33
|
+
soldier = Soldier.new
|
34
|
+
@weapon.when_receiving(:attack).with(soldier).return(5)
|
35
|
+
|
36
|
+
@soldier.attack(soldier, @weapon).should.equal 5
|
37
|
+
|
38
|
+
@weapon.did_receive?(:attack).with(soldier).should.be.successful
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
42
|
+
soldier = Soldier.new
|
43
|
+
@weapon.when_receiving(:attack).with(soldier).return(5)
|
44
|
+
|
45
|
+
@soldier.attack(soldier, @weapon).should.equal 5
|
46
|
+
|
47
|
+
@weapon.did_receive?(:attack).with(Soldier.new).should.not.be.successful
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should work with an expectation with any arguments" do
|
51
|
+
@weapon.when_receiving(:damage).return(5)
|
52
|
+
|
53
|
+
@soldier.is_killed_by?(@weapon).should.be.true?
|
54
|
+
@weapon.did_receive?(:damage).should.be.successful
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should work with an expectation getting different method call result" do
|
58
|
+
@weapon.when_receiving(:damage).return(2)
|
59
|
+
|
60
|
+
@soldier.is_killed_by?(@weapon).should.be.false?
|
61
|
+
@weapon.did_receive?(:damage).should.be.successful
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should work for an assertion on a specific argument" do
|
65
|
+
@weapon.when_receiving(:damage).return(2)
|
66
|
+
|
67
|
+
@soldier.is_killed_by?(@weapon).should.be.false?
|
68
|
+
@weapon.did_receive?(:damage).should.be.successful
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "when isolating CLR classes" do
|
74
|
+
|
75
|
+
before do
|
76
|
+
@weapon = Dagger.new
|
77
|
+
@ninja = Caricature::Isolation.for(ClrModels::Ninja)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should work without expectations" do
|
81
|
+
result = @weapon.attack @ninja
|
82
|
+
result.should.equal 0
|
83
|
+
|
84
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should work for expectations with an argument constraint" do
|
88
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
89
|
+
|
90
|
+
@weapon.attack(@ninja).should.equal 5
|
91
|
+
|
92
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
96
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
97
|
+
|
98
|
+
@weapon.attack(Soldier.new).should.equal 8
|
99
|
+
|
100
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
104
|
+
ninja = ClrModels::Ninja.new
|
105
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
106
|
+
|
107
|
+
@weapon.attack(@ninja).should.equal 5
|
108
|
+
|
109
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
113
|
+
ninja = ClrModels::Ninja.new
|
114
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
115
|
+
|
116
|
+
@weapon.attack(@ninja).should.equal 5
|
117
|
+
|
118
|
+
@ninja.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should work with an expectation for any arguments" do
|
122
|
+
@ninja.when_receiving(:survive_attack_with).return(5)
|
123
|
+
|
124
|
+
result = @weapon.attack @ninja
|
125
|
+
result.should.equal 5
|
126
|
+
|
127
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should work with an assertion for specific arguments" do
|
131
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
132
|
+
method_should.return(5)
|
133
|
+
end
|
134
|
+
|
135
|
+
result = @weapon.attack @ninja
|
136
|
+
result.should.equal 5
|
137
|
+
|
138
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should fail for an assertion with wrong arguments" do
|
142
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
143
|
+
method_should.return(5)
|
144
|
+
end
|
145
|
+
|
146
|
+
result = @weapon.attack @ninja
|
147
|
+
result.should.equal 5
|
148
|
+
|
149
|
+
@ninja.
|
150
|
+
did_receive?(:survive_attack_with).
|
151
|
+
with(Caricature::Isolation.for(ClrModels::IWeapon)).
|
152
|
+
should.not.be.successful
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "when isolating CLR instances" do
|
158
|
+
|
159
|
+
before do
|
160
|
+
@weapon = Dagger.new
|
161
|
+
@ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should work without expectations" do
|
165
|
+
result = @weapon.attack @ninja
|
166
|
+
result.should.equal 0
|
167
|
+
|
168
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should work for expectations with an argument constraint" do
|
172
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
173
|
+
|
174
|
+
@weapon.attack(@ninja).should.equal 5
|
175
|
+
|
176
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
180
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
181
|
+
|
182
|
+
@weapon.attack(Soldier.new).should.equal 8
|
183
|
+
|
184
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
188
|
+
ninja = ClrModels::Ninja.new
|
189
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
190
|
+
|
191
|
+
@weapon.attack(@ninja).should.equal 5
|
192
|
+
|
193
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
197
|
+
ninja = ClrModels::Ninja.new
|
198
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
199
|
+
|
200
|
+
@weapon.attack(@ninja).should.equal 5
|
201
|
+
|
202
|
+
@ninja.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should work with an expectation for any arguments" do
|
206
|
+
@ninja.when_receiving(:survive_attack_with).return(5)
|
207
|
+
|
208
|
+
result = @weapon.attack @ninja
|
209
|
+
result.should.equal 5
|
210
|
+
|
211
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should fail for an assertion for specific arguments" do
|
215
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
216
|
+
method_should.return(5)
|
217
|
+
end
|
218
|
+
|
219
|
+
result = @weapon.attack @ninja
|
220
|
+
result.should.equal 5
|
221
|
+
var = @ninja.did_receive?(:survive_attack_with).with(:any)
|
222
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../bacon_helper"
|
2
|
+
|
3
|
+
describe "CLR to CLR interactions" do
|
4
|
+
|
5
|
+
describe "when isolating CLR classes" do
|
6
|
+
|
7
|
+
describe "that have an indexer" do
|
8
|
+
before do
|
9
|
+
@cons = ClrModels::IndexerCaller.new
|
10
|
+
@ind = Caricature::Isolation.for(ClrModels::IndexerContained)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should work without expectations" do
|
14
|
+
@cons.call_index_on_class(@ind, "key1").should.be.nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work with an expectation" do
|
18
|
+
@ind.when_receiving(:__getitem__).return("5")
|
19
|
+
|
20
|
+
@cons.call_index_on_class(@ind, "key1").should.equal "5"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,260 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../bacon_helper"
|
2
|
+
|
3
|
+
describe "Ruby to Ruby interactions" do
|
4
|
+
|
5
|
+
describe "when isolating Ruby classes" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@dagger = Dagger.new
|
9
|
+
@soldier = Caricature::Isolation.for(Soldier)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should work without expectations" do
|
13
|
+
result = @dagger.attack @soldier
|
14
|
+
result.should.equal nil
|
15
|
+
|
16
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should work for expectations with an argument constraint" do
|
20
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
21
|
+
|
22
|
+
@dagger.attack(@soldier).should.equal 5
|
23
|
+
|
24
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
28
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
29
|
+
|
30
|
+
@dagger.attack(Soldier.new).should.equal 8
|
31
|
+
|
32
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
36
|
+
soldier = Soldier.new
|
37
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
38
|
+
|
39
|
+
@dagger.attack(@soldier).should.equal 5
|
40
|
+
|
41
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
45
|
+
soldier = Soldier.new
|
46
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
47
|
+
|
48
|
+
@dagger.attack(@soldier).should.equal 5
|
49
|
+
|
50
|
+
@soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should work with an expectation for any arguments" do
|
54
|
+
@soldier.when_receiving(:survive_attack_with).return(5)
|
55
|
+
|
56
|
+
result = @dagger.attack @soldier
|
57
|
+
result.should.equal 5
|
58
|
+
|
59
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should work with an assertion for specific arguments" do
|
63
|
+
@soldier.when_receiving(:survive_attack_with) do |method_should|
|
64
|
+
method_should.return(5)
|
65
|
+
end
|
66
|
+
|
67
|
+
result = @dagger.attack @soldier
|
68
|
+
result.should.equal 5
|
69
|
+
|
70
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should fail for an assertion with wrong arguments" do
|
74
|
+
@soldier.when_receiving(:survive_attack_with) do |method_should|
|
75
|
+
method_should.return(5)
|
76
|
+
end
|
77
|
+
|
78
|
+
result = @dagger.attack @soldier
|
79
|
+
result.should.equal 5
|
80
|
+
|
81
|
+
@soldier.
|
82
|
+
did_receive?(:survive_attack_with).
|
83
|
+
with(Caricature::Isolation.for(Dagger)).
|
84
|
+
should.not.be.successful
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "when isolating Ruby classes with class members" do
|
90
|
+
|
91
|
+
before do
|
92
|
+
@dagger = Dagger.new
|
93
|
+
@soldier = Caricature::Isolation.for(SoldierWithClassMembers)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should work without expectations" do
|
97
|
+
result = @dagger.attack @soldier
|
98
|
+
result.should.equal nil
|
99
|
+
|
100
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should work for expectations with an argument constraint" do
|
104
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
105
|
+
|
106
|
+
@dagger.attack(@soldier).should.equal 5
|
107
|
+
|
108
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should work for an expctation on a class method without an argument constraint" do
|
112
|
+
@soldier.when_class_receives(:class_name).return(5)
|
113
|
+
|
114
|
+
@soldier.class.class_name.should.equal 5
|
115
|
+
|
116
|
+
@soldier.did_class_receive?(:class_name).should.be.successful
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
120
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
121
|
+
|
122
|
+
@dagger.attack(Soldier.new).should.equal 8
|
123
|
+
|
124
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
128
|
+
soldier = Soldier.new
|
129
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
130
|
+
|
131
|
+
@dagger.attack(@soldier).should.equal 5
|
132
|
+
|
133
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
137
|
+
soldier = Soldier.new
|
138
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
139
|
+
|
140
|
+
@dagger.attack(@soldier).should.equal 5
|
141
|
+
|
142
|
+
@soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should work with an expectation for any arguments" do
|
146
|
+
@soldier.when_receiving(:survive_attack_with).return(5)
|
147
|
+
|
148
|
+
result = @dagger.attack @soldier
|
149
|
+
result.should.equal 5
|
150
|
+
|
151
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should work with an assertion for specific arguments" do
|
155
|
+
@soldier.when_receiving(:survive_attack_with) do |method_should|
|
156
|
+
method_should.return(5)
|
157
|
+
end
|
158
|
+
|
159
|
+
result = @dagger.attack @soldier
|
160
|
+
result.should.equal 5
|
161
|
+
|
162
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should fail for an assertion with wrong arguments" do
|
166
|
+
@soldier.when_receiving(:survive_attack_with) do |method_should|
|
167
|
+
method_should.return(5)
|
168
|
+
end
|
169
|
+
|
170
|
+
result = @dagger.attack @soldier
|
171
|
+
result.should.equal 5
|
172
|
+
|
173
|
+
@soldier.
|
174
|
+
did_receive?(:survive_attack_with).
|
175
|
+
with(Caricature::Isolation.for(Dagger)).
|
176
|
+
should.not.be.successful
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "when isolating Ruby instances" do
|
182
|
+
|
183
|
+
before do
|
184
|
+
@dagger = Dagger.new
|
185
|
+
@soldier = Caricature::Isolation.for(Soldier.new)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should work without expectations" do
|
189
|
+
result = @dagger.attack @soldier
|
190
|
+
result.should.equal nil
|
191
|
+
|
192
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should work for expectations with an argument constraint" do
|
196
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
197
|
+
|
198
|
+
@dagger.attack(@soldier).should.equal 5
|
199
|
+
|
200
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
204
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
205
|
+
|
206
|
+
@dagger.attack(Soldier.new).should.equal 8
|
207
|
+
|
208
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
212
|
+
soldier = Soldier.new
|
213
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
214
|
+
|
215
|
+
@dagger.attack(@soldier).should.equal 5
|
216
|
+
|
217
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
221
|
+
soldier = Soldier.new
|
222
|
+
@soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
|
223
|
+
|
224
|
+
@dagger.attack(@soldier).should.equal 5
|
225
|
+
|
226
|
+
@soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should work with an expectation for any arguments" do
|
230
|
+
@soldier.when_receiving(:survive_attack_with).return(5)
|
231
|
+
|
232
|
+
result = @dagger.attack @soldier
|
233
|
+
result.should.equal 5
|
234
|
+
|
235
|
+
@soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should fail for an assertion for specific arguments" do
|
239
|
+
@soldier.when_receiving(:survive_attack_with) do |method_should|
|
240
|
+
method_should.return(5)
|
241
|
+
end
|
242
|
+
|
243
|
+
result = @dagger.attack @soldier
|
244
|
+
result.should.equal 5
|
245
|
+
var = @soldier.did_receive?(:survive_attack_with).with(:any)
|
246
|
+
@soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should allow to delegate the method call to the real instance (partial mock)" do
|
250
|
+
@soldier.when_receiving(:survive_attack_with).super_after
|
251
|
+
|
252
|
+
result = @dagger.attack @soldier
|
253
|
+
result.should.equal 8
|
254
|
+
|
255
|
+
@soldier.did_receive?(:survive_attack_with).should.be.successful
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
data/spec/models/ClrModels.cs
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
using System;
|
2
|
+
using System.Collections.Generic;
|
2
3
|
|
3
4
|
namespace ClrModels{
|
4
5
|
public interface IWeapon{
|
@@ -182,4 +183,35 @@ public class Sword : IWeapon{
|
|
182
183
|
return MyClassWithAStatic.GoodByeWorld();
|
183
184
|
}
|
184
185
|
}
|
186
|
+
|
187
|
+
public class IndexerContained{
|
188
|
+
|
189
|
+
private Dictionary<string, string> _inner = new Dictionary<string, string>{
|
190
|
+
{ "key1", "value1" },
|
191
|
+
{ "key2", "value2" },
|
192
|
+
{ "key3", "value3" },
|
193
|
+
{ "key4", "value4" }
|
194
|
+
};
|
195
|
+
|
196
|
+
public virtual string this[string name]{
|
197
|
+
get { return _inner[name]; }
|
198
|
+
set { _inner[name] = value; }
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
public class IndexerCaller{
|
203
|
+
|
204
|
+
public string CallIndexOnClass(IndexerContained klass, string name){
|
205
|
+
return klass[name];
|
206
|
+
}
|
207
|
+
|
208
|
+
public string CallIndexOnInterface(IHaveAnIndexer klass, string name){
|
209
|
+
return klass[name];
|
210
|
+
}
|
211
|
+
|
212
|
+
}
|
213
|
+
|
214
|
+
public interface IHaveAnIndexer{
|
215
|
+
string this[string name]{ get; set; }
|
216
|
+
}
|
185
217
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + "
|
1
|
+
require File.dirname(__FILE__) + "/../bacon_helper"
|
2
2
|
|
3
3
|
describe "Caricature::TypeDescriptor" do
|
4
4
|
|
@@ -89,6 +89,16 @@ describe "Caricature::ClrInterfaceDescriptor" do
|
|
89
89
|
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
90
90
|
end
|
91
91
|
|
92
|
+
it "should correctly identify indexers" do
|
93
|
+
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
94
|
+
des.instance_members.select { |mem| mem.name == "__getitem__" }.should.not.be.empty
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should correctly identify indexers" do
|
98
|
+
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
99
|
+
des.instance_members.select { |mem| mem.name == "__setitem__" }.should.not.be.empty
|
100
|
+
end
|
101
|
+
|
92
102
|
end
|
93
103
|
|
94
104
|
describe "Caricature::ClrClassDescriptor" do
|
@@ -113,7 +123,15 @@ describe "Caricature::ClrClassDescriptor" do
|
|
113
123
|
@des.instance_members.select { |mem| mem.name == "another_method" }.should.not.be.empty
|
114
124
|
end
|
115
125
|
|
126
|
+
it "should correctly identify indexers" do
|
127
|
+
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
128
|
+
des.instance_members.select { |mem| mem.name == "__getitem__" }.should.not.be.empty
|
129
|
+
end
|
116
130
|
|
131
|
+
it "should correctly identify indexers" do
|
132
|
+
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
133
|
+
des.instance_members.select { |mem| mem.name == "__setitem__" }.should.not.be.empty
|
134
|
+
end
|
117
135
|
|
118
136
|
end
|
119
137
|
|