caricature 0.7.6 → 0.7.7
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/caricature.gemspec +3 -3
- data/lib/bin/Workarounds.dll.mdb +0 -0
- data/lib/caricature.rb +25 -25
- data/lib/caricature/clr.rb +6 -6
- data/lib/caricature/clr/aspnet_mvc.rb +54 -54
- data/lib/caricature/core_ext.rb +10 -10
- data/lib/caricature/core_ext/array.rb +9 -9
- data/lib/caricature/core_ext/class.rb +31 -14
- data/lib/caricature/core_ext/hash.rb +12 -12
- data/lib/caricature/core_ext/module.rb +14 -14
- data/lib/caricature/core_ext/object.rb +76 -18
- data/lib/caricature/core_ext/string.rb +16 -16
- data/lib/caricature/core_ext/system/string.rb +20 -20
- data/lib/caricature/core_ext/system/type.rb +26 -26
- data/lib/caricature/descriptor.rb +73 -73
- data/lib/caricature/expectation.rb +264 -263
- data/lib/caricature/isolation.rb +143 -143
- data/lib/caricature/isolator.rb +302 -302
- data/lib/caricature/messenger.rb +67 -67
- data/lib/caricature/method_call_recorder.rb +228 -228
- data/lib/caricature/verification.rb +60 -60
- data/lib/caricature/version.rb +1 -1
- data/spec/bacon/integration/clr_to_clr_spec.rb +4 -4
- data/spec/bacon/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/bacon/integration/event_spec.rb +2 -2
- data/spec/bacon/integration/ruby_to_ruby_spec.rb +270 -270
- data/spec/bacon/integration/syntax_spec.rb +43 -0
- data/spec/bacon/unit/core_ext_spec.rb +87 -87
- data/spec/bacon/unit/expectation_spec.rb +300 -300
- data/spec/bacon/unit/interop_spec.rb +29 -29
- data/spec/bacon/unit/isolation_spec.rb +86 -86
- data/spec/bacon/unit/isolator_spec.rb +219 -219
- data/spec/bacon/unit/messaging_spec.rb +310 -310
- data/spec/bacon/unit/method_call_spec.rb +342 -342
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/rspec/unit/event_spec.rb +1 -1
- metadata +31 -11
- data/spec/models.notused/ClrModels.cs +0 -241
- data/spec/models.notused/ruby_models.rb +0 -151
@@ -1,311 +1,311 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
class EmptyExpectations
|
4
|
-
|
5
|
-
def find(method_name, *args, &b)
|
6
|
-
nil
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class ReturnValueExpecation
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@super_before_called = false
|
14
|
-
@call_super_called = false
|
15
|
-
@called_super_after = false
|
16
|
-
end
|
17
|
-
|
18
|
-
def block
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def super_before?
|
23
|
-
@super_before_called = true
|
24
|
-
false
|
25
|
-
end
|
26
|
-
|
27
|
-
def call_super?
|
28
|
-
@call_super_called = true
|
29
|
-
false
|
30
|
-
end
|
31
|
-
|
32
|
-
def have_called_super_before?
|
33
|
-
@super_before_called
|
34
|
-
end
|
35
|
-
|
36
|
-
def have_called_call_super?
|
37
|
-
@super_before_called && @called_super_after
|
38
|
-
end
|
39
|
-
|
40
|
-
def execute(*args)
|
41
|
-
@called_super_after = !@call_super_called
|
42
|
-
5
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class ReturnValueExpectations
|
47
|
-
|
48
|
-
def expectation
|
49
|
-
@expectation ||= ReturnValueExpecation.new
|
50
|
-
@expectation
|
51
|
-
end
|
52
|
-
def find(method_name, *args, &b)
|
53
|
-
return expectation if method_name == :a_message
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class PassThruBlockExpectation
|
59
|
-
|
60
|
-
def block
|
61
|
-
@block
|
62
|
-
end
|
63
|
-
|
64
|
-
def block=(val)
|
65
|
-
@block=val
|
66
|
-
end
|
67
|
-
|
68
|
-
def block_args
|
69
|
-
[5,6,7]
|
70
|
-
end
|
71
|
-
|
72
|
-
def execute(*args, &b)
|
73
|
-
b.call *block_args
|
74
|
-
end
|
75
|
-
|
76
|
-
def super_before?
|
77
|
-
false
|
78
|
-
end
|
79
|
-
|
80
|
-
def call_super?
|
81
|
-
false
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
class CallingBlock
|
87
|
-
def a_message(*args, &b)
|
88
|
-
b.call(7,8,9)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class BlockExpectation
|
93
|
-
def block
|
94
|
-
lambda { |*args| return args }
|
95
|
-
end
|
96
|
-
|
97
|
-
def super_before?
|
98
|
-
false
|
99
|
-
end
|
100
|
-
|
101
|
-
def call_super?
|
102
|
-
true
|
103
|
-
end
|
104
|
-
|
105
|
-
def execute(*args, &b)
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
class BlockExpectations
|
112
|
-
|
113
|
-
def initialize(pass_thru=true)
|
114
|
-
@pass_thru = pass_thru
|
115
|
-
end
|
116
|
-
|
117
|
-
def expectation
|
118
|
-
@expectation ||= (@pass_thru ? PassThruBlockExpectation.new : BlockExpectation.new)
|
119
|
-
@expectation
|
120
|
-
end
|
121
|
-
def find(method_name, *args, &b)
|
122
|
-
return expectation if method_name == :a_message
|
123
|
-
nil
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
describe "Caricature::Messenger strategies" do
|
129
|
-
|
130
|
-
describe "Caricature::RubyMessenger" do
|
131
|
-
|
132
|
-
it "should return nil for any method name not in the expectation collection" do
|
133
|
-
messenger = Caricature::RubyMessenger.new EmptyExpectations.new
|
134
|
-
messenger.deliver(:a_message, nil).should.be.nil
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "when an expectation with a return value has been defined" do
|
138
|
-
|
139
|
-
before do
|
140
|
-
@messenger = Caricature::RubyMessenger.new ReturnValueExpectations.new
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should return the a value when specified by the expecation" do
|
144
|
-
@messenger.deliver(:a_message, nil).should.not.be.nil
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should return the value specified by the expecation" do
|
148
|
-
@messenger.deliver(:a_message, nil).should.equal 5
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should call super_before before executing the expectation" do
|
152
|
-
@messenger.deliver(:a_message, nil)
|
153
|
-
@messenger.expectations.expectation.should.have_called_super_before
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should call call_super? after executing the expectation" do
|
157
|
-
@messenger.deliver(:a_message, nil)
|
158
|
-
@messenger.expectations.expectation.should.have_called_call_super
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "when an expectation with a block has been defined" do
|
164
|
-
|
165
|
-
it "should invoke the block that is passed with the args from the expectation only once" do
|
166
|
-
messenger = Caricature::RubyMessenger.new BlockExpectations.new
|
167
|
-
messenger.recorder = Caricature::MethodCallRecorder.new
|
168
|
-
counter = 0
|
169
|
-
arguments = []
|
170
|
-
messenger.deliver(:a_message, nil) do |*args|
|
171
|
-
counter += 1
|
172
|
-
arguments = args
|
173
|
-
end
|
174
|
-
counter.should == 1
|
175
|
-
[5,6,7].should == arguments
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should call the block that is defined on the expectation by super when call super is enabled" do
|
179
|
-
exp = BlockExpectations.new(false)
|
180
|
-
messenger = Caricature::RubyMessenger.new exp, CallingBlock.new
|
181
|
-
result = messenger.deliver(:a_message, nil, exp.expectation)
|
182
|
-
[7,8,9].should == result
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
describe "Caricature::ClrClassMessenger" do
|
191
|
-
|
192
|
-
it "should return nil for any method name not in the expectation collection" do
|
193
|
-
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
194
|
-
messenger.deliver(:a_message, nil).should.be.nil
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should return the default value for a value type return type" do
|
198
|
-
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
199
|
-
messenger.deliver(:a_message, System::Int32.to_clr_type).should.equal 0
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "when an expectation with a return value has been defined" do
|
203
|
-
|
204
|
-
before do
|
205
|
-
@messenger = Caricature::ClrClassMessenger.new ReturnValueExpectations.new
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should return the a value when specified by the expecation" do
|
209
|
-
@messenger.deliver(:a_message, nil).should.not.be.nil
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should return the value specified by the expecation" do
|
213
|
-
@messenger.deliver(:a_message, nil).should.equal 5
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should call super_before before executing the expectation" do
|
217
|
-
@messenger.deliver(:a_message, nil)
|
218
|
-
@messenger.expectations.expectation.should.have_called_super_before
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should call call_super? after executing the expectation" do
|
222
|
-
@messenger.deliver(:a_message, nil)
|
223
|
-
@messenger.expectations.expectation.should.have_called_call_super
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "when an expectation with a block has been defined" do
|
229
|
-
|
230
|
-
it "should invoke the block that is passed with the args from the expectation only once" do
|
231
|
-
messenger = Caricature::ClrClassMessenger.new BlockExpectations.new
|
232
|
-
messenger.recorder = Caricature::MethodCallRecorder.new
|
233
|
-
counter = 0
|
234
|
-
arguments = []
|
235
|
-
messenger.deliver(:a_message, nil) do |*args|
|
236
|
-
counter += 1
|
237
|
-
arguments = args
|
238
|
-
end
|
239
|
-
counter.should == 1
|
240
|
-
[5,6,7].should == arguments
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should call the block that is defined on the expectation by super when call super is enabled" do
|
244
|
-
messenger = Caricature::ClrClassMessenger.new BlockExpectations.new(false), CallingBlock.new
|
245
|
-
result = messenger.deliver(:a_message, nil)
|
246
|
-
[7,8,9].should == result
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
252
|
-
|
253
|
-
describe "Caricature::ClrInterfaceMessenger" do
|
254
|
-
|
255
|
-
it "should return nil for any method name not in the expectation collection" do
|
256
|
-
messenger = Caricature::ClrInterfaceMessenger.new EmptyExpectations.new
|
257
|
-
messenger.deliver(:a_message, nil).should.be.nil
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should return the default value for a value type return type" do
|
261
|
-
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
262
|
-
messenger.deliver(:a_message, System::Int32.to_clr_type).should.equal 0
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "when an expectation with a return value has been defined" do
|
266
|
-
|
267
|
-
before do
|
268
|
-
@messenger = Caricature::ClrInterfaceMessenger.new ReturnValueExpectations.new
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should return the a value when specified by the expecation" do
|
272
|
-
@messenger.deliver(:a_message, nil).should.not.be.nil
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should return the value specified by the expecation" do
|
276
|
-
@messenger.deliver(:a_message, nil).should.equal 5
|
277
|
-
end
|
278
|
-
|
279
|
-
it "should not call super_before before executing the expectation" do
|
280
|
-
@messenger.deliver(:a_message, nil)
|
281
|
-
@messenger.expectations.expectation.should.not.have_called_super_before
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should not call call_super? after executing the expectation" do
|
285
|
-
@messenger.deliver(:a_message, nil)
|
286
|
-
@messenger.expectations.expectation.should.not.have_called_call_super
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
describe "when an expectation with a block has been defined" do
|
292
|
-
|
293
|
-
it "should invoke the block that is passed with the args from the expectation only once" do
|
294
|
-
exp = BlockExpectations.new
|
295
|
-
messenger = Caricature::ClrInterfaceMessenger.new exp
|
296
|
-
messenger.recorder = Caricature::MethodCallRecorder.new
|
297
|
-
counter = 0
|
298
|
-
arguments = []
|
299
|
-
messenger.deliver(:a_message, nil, exp.expectation) do |*args|
|
300
|
-
counter += 1
|
301
|
-
arguments = args
|
302
|
-
end
|
303
|
-
counter.should == 1
|
304
|
-
[5,6,7].should == arguments
|
305
|
-
end
|
306
|
-
|
307
|
-
end
|
308
|
-
|
309
|
-
end
|
310
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
class EmptyExpectations
|
4
|
+
|
5
|
+
def find(method_name, *args, &b)
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ReturnValueExpecation
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@super_before_called = false
|
14
|
+
@call_super_called = false
|
15
|
+
@called_super_after = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def block
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def super_before?
|
23
|
+
@super_before_called = true
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def call_super?
|
28
|
+
@call_super_called = true
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def have_called_super_before?
|
33
|
+
@super_before_called
|
34
|
+
end
|
35
|
+
|
36
|
+
def have_called_call_super?
|
37
|
+
@super_before_called && @called_super_after
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(*args)
|
41
|
+
@called_super_after = !@call_super_called
|
42
|
+
5
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class ReturnValueExpectations
|
47
|
+
|
48
|
+
def expectation
|
49
|
+
@expectation ||= ReturnValueExpecation.new
|
50
|
+
@expectation
|
51
|
+
end
|
52
|
+
def find(method_name, *args, &b)
|
53
|
+
return expectation if method_name == :a_message
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class PassThruBlockExpectation
|
59
|
+
|
60
|
+
def block
|
61
|
+
@block
|
62
|
+
end
|
63
|
+
|
64
|
+
def block=(val)
|
65
|
+
@block=val
|
66
|
+
end
|
67
|
+
|
68
|
+
def block_args
|
69
|
+
[5,6,7]
|
70
|
+
end
|
71
|
+
|
72
|
+
def execute(*args, &b)
|
73
|
+
b.call *block_args
|
74
|
+
end
|
75
|
+
|
76
|
+
def super_before?
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def call_super?
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
class CallingBlock
|
87
|
+
def a_message(*args, &b)
|
88
|
+
b.call(7,8,9)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class BlockExpectation
|
93
|
+
def block
|
94
|
+
lambda { |*args| return args }
|
95
|
+
end
|
96
|
+
|
97
|
+
def super_before?
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
def call_super?
|
102
|
+
true
|
103
|
+
end
|
104
|
+
|
105
|
+
def execute(*args, &b)
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
class BlockExpectations
|
112
|
+
|
113
|
+
def initialize(pass_thru=true)
|
114
|
+
@pass_thru = pass_thru
|
115
|
+
end
|
116
|
+
|
117
|
+
def expectation
|
118
|
+
@expectation ||= (@pass_thru ? PassThruBlockExpectation.new : BlockExpectation.new)
|
119
|
+
@expectation
|
120
|
+
end
|
121
|
+
def find(method_name, *args, &b)
|
122
|
+
return expectation if method_name == :a_message
|
123
|
+
nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
describe "Caricature::Messenger strategies" do
|
129
|
+
|
130
|
+
describe "Caricature::RubyMessenger" do
|
131
|
+
|
132
|
+
it "should return nil for any method name not in the expectation collection" do
|
133
|
+
messenger = Caricature::RubyMessenger.new EmptyExpectations.new
|
134
|
+
messenger.deliver(:a_message, nil).should.be.nil
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "when an expectation with a return value has been defined" do
|
138
|
+
|
139
|
+
before do
|
140
|
+
@messenger = Caricature::RubyMessenger.new ReturnValueExpectations.new
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return the a value when specified by the expecation" do
|
144
|
+
@messenger.deliver(:a_message, nil).should.not.be.nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return the value specified by the expecation" do
|
148
|
+
@messenger.deliver(:a_message, nil).should.equal 5
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should call super_before before executing the expectation" do
|
152
|
+
@messenger.deliver(:a_message, nil)
|
153
|
+
@messenger.expectations.expectation.should.have_called_super_before
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should call call_super? after executing the expectation" do
|
157
|
+
@messenger.deliver(:a_message, nil)
|
158
|
+
@messenger.expectations.expectation.should.have_called_call_super
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "when an expectation with a block has been defined" do
|
164
|
+
|
165
|
+
it "should invoke the block that is passed with the args from the expectation only once" do
|
166
|
+
messenger = Caricature::RubyMessenger.new BlockExpectations.new
|
167
|
+
messenger.recorder = Caricature::MethodCallRecorder.new
|
168
|
+
counter = 0
|
169
|
+
arguments = []
|
170
|
+
messenger.deliver(:a_message, nil) do |*args|
|
171
|
+
counter += 1
|
172
|
+
arguments = args
|
173
|
+
end
|
174
|
+
counter.should == 1
|
175
|
+
[5,6,7].should == arguments
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should call the block that is defined on the expectation by super when call super is enabled" do
|
179
|
+
exp = BlockExpectations.new(false)
|
180
|
+
messenger = Caricature::RubyMessenger.new exp, CallingBlock.new
|
181
|
+
result = messenger.deliver(:a_message, nil, exp.expectation)
|
182
|
+
[7,8,9].should == result
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "Caricature::ClrClassMessenger" do
|
191
|
+
|
192
|
+
it "should return nil for any method name not in the expectation collection" do
|
193
|
+
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
194
|
+
messenger.deliver(:a_message, nil).should.be.nil
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return the default value for a value type return type" do
|
198
|
+
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
199
|
+
messenger.deliver(:a_message, System::Int32.to_clr_type).should.equal 0
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "when an expectation with a return value has been defined" do
|
203
|
+
|
204
|
+
before do
|
205
|
+
@messenger = Caricature::ClrClassMessenger.new ReturnValueExpectations.new
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should return the a value when specified by the expecation" do
|
209
|
+
@messenger.deliver(:a_message, nil).should.not.be.nil
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return the value specified by the expecation" do
|
213
|
+
@messenger.deliver(:a_message, nil).should.equal 5
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should call super_before before executing the expectation" do
|
217
|
+
@messenger.deliver(:a_message, nil)
|
218
|
+
@messenger.expectations.expectation.should.have_called_super_before
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should call call_super? after executing the expectation" do
|
222
|
+
@messenger.deliver(:a_message, nil)
|
223
|
+
@messenger.expectations.expectation.should.have_called_call_super
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "when an expectation with a block has been defined" do
|
229
|
+
|
230
|
+
it "should invoke the block that is passed with the args from the expectation only once" do
|
231
|
+
messenger = Caricature::ClrClassMessenger.new BlockExpectations.new
|
232
|
+
messenger.recorder = Caricature::MethodCallRecorder.new
|
233
|
+
counter = 0
|
234
|
+
arguments = []
|
235
|
+
messenger.deliver(:a_message, nil) do |*args|
|
236
|
+
counter += 1
|
237
|
+
arguments = args
|
238
|
+
end
|
239
|
+
counter.should == 1
|
240
|
+
[5,6,7].should == arguments
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should call the block that is defined on the expectation by super when call super is enabled" do
|
244
|
+
messenger = Caricature::ClrClassMessenger.new BlockExpectations.new(false), CallingBlock.new
|
245
|
+
result = messenger.deliver(:a_message, nil)
|
246
|
+
[7,8,9].should == result
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "Caricature::ClrInterfaceMessenger" do
|
254
|
+
|
255
|
+
it "should return nil for any method name not in the expectation collection" do
|
256
|
+
messenger = Caricature::ClrInterfaceMessenger.new EmptyExpectations.new
|
257
|
+
messenger.deliver(:a_message, nil).should.be.nil
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return the default value for a value type return type" do
|
261
|
+
messenger = Caricature::ClrClassMessenger.new EmptyExpectations.new
|
262
|
+
messenger.deliver(:a_message, System::Int32.to_clr_type).should.equal 0
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "when an expectation with a return value has been defined" do
|
266
|
+
|
267
|
+
before do
|
268
|
+
@messenger = Caricature::ClrInterfaceMessenger.new ReturnValueExpectations.new
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should return the a value when specified by the expecation" do
|
272
|
+
@messenger.deliver(:a_message, nil).should.not.be.nil
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should return the value specified by the expecation" do
|
276
|
+
@messenger.deliver(:a_message, nil).should.equal 5
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should not call super_before before executing the expectation" do
|
280
|
+
@messenger.deliver(:a_message, nil)
|
281
|
+
@messenger.expectations.expectation.should.not.have_called_super_before
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should not call call_super? after executing the expectation" do
|
285
|
+
@messenger.deliver(:a_message, nil)
|
286
|
+
@messenger.expectations.expectation.should.not.have_called_call_super
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "when an expectation with a block has been defined" do
|
292
|
+
|
293
|
+
it "should invoke the block that is passed with the args from the expectation only once" do
|
294
|
+
exp = BlockExpectations.new
|
295
|
+
messenger = Caricature::ClrInterfaceMessenger.new exp
|
296
|
+
messenger.recorder = Caricature::MethodCallRecorder.new
|
297
|
+
counter = 0
|
298
|
+
arguments = []
|
299
|
+
messenger.deliver(:a_message, nil, exp.expectation) do |*args|
|
300
|
+
counter += 1
|
301
|
+
arguments = args
|
302
|
+
end
|
303
|
+
counter.should == 1
|
304
|
+
[5,6,7].should == arguments
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
311
|
end
|