caricature 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/caricature.gemspec +3 -3
  2. data/lib/bin/Workarounds.dll.mdb +0 -0
  3. data/lib/caricature.rb +25 -25
  4. data/lib/caricature/clr.rb +6 -6
  5. data/lib/caricature/clr/aspnet_mvc.rb +54 -54
  6. data/lib/caricature/core_ext.rb +10 -10
  7. data/lib/caricature/core_ext/array.rb +9 -9
  8. data/lib/caricature/core_ext/class.rb +31 -14
  9. data/lib/caricature/core_ext/hash.rb +12 -12
  10. data/lib/caricature/core_ext/module.rb +14 -14
  11. data/lib/caricature/core_ext/object.rb +76 -18
  12. data/lib/caricature/core_ext/string.rb +16 -16
  13. data/lib/caricature/core_ext/system/string.rb +20 -20
  14. data/lib/caricature/core_ext/system/type.rb +26 -26
  15. data/lib/caricature/descriptor.rb +73 -73
  16. data/lib/caricature/expectation.rb +264 -263
  17. data/lib/caricature/isolation.rb +143 -143
  18. data/lib/caricature/isolator.rb +302 -302
  19. data/lib/caricature/messenger.rb +67 -67
  20. data/lib/caricature/method_call_recorder.rb +228 -228
  21. data/lib/caricature/verification.rb +60 -60
  22. data/lib/caricature/version.rb +1 -1
  23. data/spec/bacon/integration/clr_to_clr_spec.rb +4 -4
  24. data/spec/bacon/integration/clr_to_ruby_spec.rb +227 -227
  25. data/spec/bacon/integration/event_spec.rb +2 -2
  26. data/spec/bacon/integration/ruby_to_ruby_spec.rb +270 -270
  27. data/spec/bacon/integration/syntax_spec.rb +43 -0
  28. data/spec/bacon/unit/core_ext_spec.rb +87 -87
  29. data/spec/bacon/unit/expectation_spec.rb +300 -300
  30. data/spec/bacon/unit/interop_spec.rb +29 -29
  31. data/spec/bacon/unit/isolation_spec.rb +86 -86
  32. data/spec/bacon/unit/isolator_spec.rb +219 -219
  33. data/spec/bacon/unit/messaging_spec.rb +310 -310
  34. data/spec/bacon/unit/method_call_spec.rb +342 -342
  35. data/spec/bin/ClrModels.dll.mdb +0 -0
  36. data/spec/rspec/unit/event_spec.rb +1 -1
  37. metadata +31 -11
  38. data/spec/models.notused/ClrModels.cs +0 -241
  39. data/spec/models.notused/ruby_models.rb +0 -151
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "syntax improvements" do
4
+
5
+ describe "creation from a class method" do
6
+
7
+ it "should allow creating an isolation" do
8
+ soldier = Soldier.isolate
9
+ soldier.should.not.be.nil
10
+ end
11
+
12
+ it "should allow setting an expectation with a block parameter" do
13
+ soldier = SoldierWithClassMembers.isolate(:class_name){ |exp| exp.return("overridden") }
14
+ soldier.class.class_name.should == "overridden"
15
+ end
16
+
17
+ it "should allow setting an expectation without a block parameter" do
18
+ soldier = SoldierWithClassMembers.isolate(:class_name){ returns("overridden") }
19
+ soldier.class.class_name.should == "overridden"
20
+ end
21
+
22
+ end
23
+
24
+
25
+ describe "creation from an instance method" do
26
+
27
+ it "should allow creating an isolation" do
28
+ soldier = Soldier.new.isolate
29
+ soldier.should.not.be.nil
30
+ end
31
+
32
+ it "should allow setting an expectation with a block parameter" do
33
+ soldier = Soldier.new.isolate(:name){ |exp| exp.return("overridden") }
34
+ soldier.name.should == "overridden"
35
+ end
36
+
37
+ it "should allow setting an expectation without a block parameter" do
38
+ soldier = Soldier.new.isolate(:name){ returns("overridden") }
39
+ soldier.name.should == "overridden"
40
+ end
41
+
42
+ end
43
+ end
@@ -1,87 +1,87 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "String" do
4
-
5
- it "should underscore a camel cased name" do
6
- "MockingAndStubbingForIronRuby1".underscore.should.equal "mocking_and_stubbing_for_iron_ruby1"
7
- end
8
-
9
- it "should get the class if it exists" do
10
- "String".classify.should.equal String
11
- end
12
-
13
- end
14
-
15
- describe "Module" do
16
-
17
- it "should strip the module names" do
18
- ClrModels::IExposingWarrior.demodulize.should.equal "IExposingWarrior"
19
- end
20
-
21
- it "should identify it's not a CLR type for a Ruby defined module" do
22
- Caricature.clr_type?.should.be.false?
23
- end
24
-
25
- it "should identify it's a CLR type for a CLR defined interface" do
26
- ClrModels::IExposingWarrior.clr_type?.should.be.true?
27
- end
28
-
29
- it "should identify it's a CLR type for a Ruby defined module that includes a CLR interface" do
30
- Caricature::InterfaceIncludingModule.clr_type?.should.be.true?
31
- end
32
-
33
- it "should identify it's not a CLR type for a Ruby defined module that includes a Ruby module" do
34
- Caricature::RubyModuleIncludingModule.clr_type?.should.be.false?
35
- end
36
-
37
- it "should identify it's a CLR type when an ancestor includes a CLR interface" do
38
- Caricature::InterfaceUpTheWazoo.clr_type?.should.be.true?
39
- end
40
-
41
- end
42
-
43
- describe "Class" do
44
-
45
- it "should strip the module names" do
46
- ClrModels::Ninja.demodulize.should.equal "Ninja"
47
- end
48
-
49
- it "should identify it's not a CLR type for a ruby defined type" do
50
- Soldier.clr_type?.should.be.false?
51
- end
52
-
53
- it "should identify it's not a CLR type for a ruby defined type that subclasses a Ruby class" do
54
- Caricature::SubclassingRubyClass.clr_type?.should.be.false?
55
- end
56
-
57
- it "should identify it's not a CLR type for a ruby defined type that includes only ruby modueles in its hierarchy" do
58
- Caricature::ModuleIncludingClass.clr_type?.should.be.false?
59
- end
60
-
61
- it "should identify it's a CLR type for a type defined in C#" do
62
- ClrModels::Ninja.clr_type?.should.be.true?
63
- end
64
-
65
- it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface" do
66
- Caricature::InterfaceIncludingClass.clr_type?.should.be.true?
67
- end
68
-
69
- it "should identify it's a CLR type for a type defined in Ruby that subclasses a CLR class" do
70
- Caricature::SubClassingClrClass.clr_type?.should.be.true?
71
- end
72
-
73
- it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface in its hierarchy" do
74
- Caricature::InterfaceUpTheWazooClass.clr_type?.should.be.true?
75
- end
76
-
77
- end
78
-
79
- describe "Array" do
80
-
81
- it "should convert an array to a hash" do
82
- expected = { :key1 => "value1", :key2 => "value2"}
83
- %w(key1 value1 key2 value2).to_h.should.equal expected
84
- end
85
-
86
- end
87
-
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "String" do
4
+
5
+ it "should underscore a camel cased name" do
6
+ "MockingAndStubbingForIronRuby1".underscore.should.equal "mocking_and_stubbing_for_iron_ruby1"
7
+ end
8
+
9
+ it "should get the class if it exists" do
10
+ "String".classify.should.equal String
11
+ end
12
+
13
+ end
14
+
15
+ describe "Module" do
16
+
17
+ it "should strip the module names" do
18
+ ClrModels::IExposingWarrior.demodulize.should.equal "IExposingWarrior"
19
+ end
20
+
21
+ it "should identify it's not a CLR type for a Ruby defined module" do
22
+ Caricature.clr_type?.should.be.false?
23
+ end
24
+
25
+ it "should identify it's a CLR type for a CLR defined interface" do
26
+ ClrModels::IExposingWarrior.clr_type?.should.be.true?
27
+ end
28
+
29
+ it "should identify it's a CLR type for a Ruby defined module that includes a CLR interface" do
30
+ Caricature::InterfaceIncludingModule.clr_type?.should.be.true?
31
+ end
32
+
33
+ it "should identify it's not a CLR type for a Ruby defined module that includes a Ruby module" do
34
+ Caricature::RubyModuleIncludingModule.clr_type?.should.be.false?
35
+ end
36
+
37
+ it "should identify it's a CLR type when an ancestor includes a CLR interface" do
38
+ Caricature::InterfaceUpTheWazoo.clr_type?.should.be.true?
39
+ end
40
+
41
+ end
42
+
43
+ describe "Class" do
44
+
45
+ it "should strip the module names" do
46
+ ClrModels::Ninja.demodulize.should.equal "Ninja"
47
+ end
48
+
49
+ it "should identify it's not a CLR type for a ruby defined type" do
50
+ Soldier.clr_type?.should.be.false?
51
+ end
52
+
53
+ it "should identify it's not a CLR type for a ruby defined type that subclasses a Ruby class" do
54
+ Caricature::SubclassingRubyClass.clr_type?.should.be.false?
55
+ end
56
+
57
+ it "should identify it's not a CLR type for a ruby defined type that includes only ruby modueles in its hierarchy" do
58
+ Caricature::ModuleIncludingClass.clr_type?.should.be.false?
59
+ end
60
+
61
+ it "should identify it's a CLR type for a type defined in C#" do
62
+ ClrModels::Ninja.clr_type?.should.be.true?
63
+ end
64
+
65
+ it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface" do
66
+ Caricature::InterfaceIncludingClass.clr_type?.should.be.true?
67
+ end
68
+
69
+ it "should identify it's a CLR type for a type defined in Ruby that subclasses a CLR class" do
70
+ Caricature::SubClassingClrClass.clr_type?.should.be.true?
71
+ end
72
+
73
+ it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface in its hierarchy" do
74
+ Caricature::InterfaceUpTheWazooClass.clr_type?.should.be.true?
75
+ end
76
+
77
+ end
78
+
79
+ describe "Array" do
80
+
81
+ it "should convert an array to a hash" do
82
+ expected = { :key1 => "value1", :key2 => "value2"}
83
+ %w(key1 value1 key2 value2).to_h.should.equal expected
84
+ end
85
+
86
+ end
87
+
@@ -1,301 +1,301 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "Caricature::Expectations" do
4
-
5
- end
6
-
7
- describe "Caricature::ExpectationBuilder" do
8
-
9
- it "should create an expectation builder" do
10
- builder = Caricature::ExpectationBuilder.new :some_method
11
- builder.should.not.equal nil
12
- end
13
-
14
- describe "when using all defaults" do
15
-
16
- before do
17
- builder = Caricature::ExpectationBuilder.new :some_method
18
- @expectation = builder.build
19
- end
20
-
21
- it "should have the correct method_name" do
22
- @expectation.method_name.should.equal :some_method
23
- end
24
-
25
- it "should have empty args" do
26
- @expectation.args.should.be.empty?
27
- end
28
-
29
- it "should have no super call" do
30
- @expectation.super.should.equal nil
31
- end
32
-
33
- it "should have no error args" do
34
- @expectation.error_args.should.equal nil
35
- end
36
-
37
- it "should have no return_value" do
38
- @expectation.return_value.should.equal nil
39
- end
40
-
41
- it "should have no callback" do
42
- @expectation.should.not.has_callback?
43
- end
44
-
45
- end
46
-
47
- describe "when specifying only arguments" do
48
-
49
- before do
50
- builder = Caricature::ExpectationBuilder.new :some_method
51
- builder.with(1, 2, 3)
52
- @expectation = builder.build
53
- end
54
-
55
- it "should have the correct method_name" do
56
- @expectation.method_name.should.equal :some_method
57
- end
58
-
59
- it "should have empty args" do
60
- @expectation.args.should.equal [1,2,3]
61
- end
62
-
63
- it "should have no super call" do
64
- @expectation.super.should.equal nil
65
- end
66
-
67
- it "should have no error args" do
68
- @expectation.error_args.should.equal nil
69
- end
70
-
71
- it "should have no return_value" do
72
- @expectation.return_value.should.equal nil
73
- end
74
-
75
- it "should have no callback" do
76
- @expectation.should.not.has_callback?
77
- end
78
-
79
- end
80
-
81
- describe "when specifying only a block for the return value" do
82
-
83
- before do
84
- builder = Caricature::ExpectationBuilder.new :some_method
85
- builder.return { 5 }
86
- @expectation = builder.build
87
- end
88
-
89
- it "should have the correct method_name" do
90
- @expectation.method_name.should.equal :some_method
91
- end
92
-
93
- it "should have empty args" do
94
- @expectation.args.should.be.empty?
95
- end
96
-
97
- it "should have no super call" do
98
- @expectation.super.should.equal nil
99
- end
100
-
101
- it "should have no error args" do
102
- @expectation.error_args.should.equal nil
103
- end
104
-
105
- it "should have a return callback" do
106
- @expectation.return_callback.should.not.be.nil
107
- end
108
-
109
- it "should have the correct return_value" do
110
- @expectation.return_callback.call.should.equal 5
111
- end
112
-
113
- end
114
-
115
- describe "when specifying a return value" do
116
-
117
- before do
118
- builder = Caricature::ExpectationBuilder.new :some_method
119
- builder.return 5
120
- @expectation = builder.build
121
- end
122
-
123
- it "should have the correct method_name" do
124
- @expectation.method_name.should.equal :some_method
125
- end
126
-
127
- it "should have empty args" do
128
- @expectation.args.should.be.empty?
129
- end
130
-
131
- it "should have no super call" do
132
- @expectation.super.should.equal nil
133
- end
134
-
135
- it "should have no error args" do
136
- @expectation.error_args.should.equal nil
137
- end
138
-
139
- it "should have the correct return_value" do
140
- @expectation.return_value.should.equal 5
141
- end
142
-
143
- end
144
-
145
- describe "when specifying a raise arguments" do
146
-
147
- before do
148
- @msg = "Hold on, that wasn't supposed to happen"
149
- builder = Caricature::ExpectationBuilder.new :some_method
150
- builder.raise @msg
151
- @expectation = builder.build
152
- end
153
-
154
- it "should have the correct method_name" do
155
- @expectation.method_name.should.equal :some_method
156
- end
157
-
158
- it "should have empty args" do
159
- @expectation.args.should.be.empty?
160
- end
161
-
162
- it "should have no super call" do
163
- @expectation.super.should.equal nil
164
- end
165
-
166
- it "should have no error args" do
167
- @expectation.error_args.should.equal [@msg]
168
- end
169
-
170
- it "should have the correct return_value" do
171
- @expectation.return_value.should.equal nil
172
- end
173
-
174
- end
175
-
176
- describe "when specifying a return value and telling you want a call to super before" do
177
-
178
- before do
179
- builder = Caricature::ExpectationBuilder.new :some_method
180
- builder.return(5).super_before
181
- @expectation = builder.build
182
- end
183
-
184
- it "should have the correct method_name" do
185
- @expectation.method_name.should.equal :some_method
186
- end
187
-
188
- it "should have empty args" do
189
- @expectation.args.should.be.empty?
190
- end
191
-
192
- it "should have no super call" do
193
- @expectation.super.should.equal :before
194
- end
195
-
196
- it "should have no error args" do
197
- @expectation.error_args.should.equal nil
198
- end
199
-
200
- it "should have the correct return_value" do
201
- @expectation.return_value.should.equal 5
202
- end
203
-
204
- end
205
-
206
- describe "when giving a block to the arguments constraint it should register it as a callback" do
207
-
208
- before do
209
- builder = Caricature::ExpectationBuilder.new :some_method
210
- @counter, @args = 0, []
211
- builder.with(5) do |*ags|
212
- @counter += 1
213
- @args = ags
214
- end
215
- @expectation = builder.build
216
- end
217
-
218
- it "should have a callback" do
219
- @expectation.should.has_callback?
220
- end
221
-
222
- it "should call the callback when the expectation is called" do
223
- @expectation.execute
224
- @counter.should == 1
225
- end
226
-
227
- it "should pass on the correct arguments" do
228
- @expectation.execute 1, 2, 3
229
- @args.should == [1, 2, 3]
230
- end
231
- end
232
-
233
- describe "when giving a block to a super method it should register it" do
234
-
235
- before do
236
- builder = Caricature::ExpectationBuilder.new :some_method
237
- @counter = 0
238
- builder.super_after do
239
- @counter += 1
240
- end
241
- @expectation = builder.build
242
- end
243
-
244
- it "should should have a callback" do
245
- @expectation.block.should.not.be.nil
246
- end
247
-
248
- it "should pass on the correct callback" do
249
- @expectation.block.call
250
- @counter.should == 1
251
- end
252
-
253
- end
254
-
255
- describe "when given arguments to the block pass method" do
256
-
257
- before do
258
- builder = Caricature::ExpectationBuilder.new :some_method
259
- builder.pass_block(1,2,3)
260
- @expectation = builder.build
261
- end
262
-
263
- it "should not have a block callback" do
264
- @expectation.should.not.has_block_callback
265
- end
266
-
267
- it "should should execute the block with the provided arguments when executed" do
268
- ags = []
269
- @expectation.execute do |*args|
270
- ags = args
271
- end
272
- ags.should == [1,2,3]
273
- end
274
-
275
- end
276
-
277
- describe "when given arguments to the block pass method" do
278
-
279
- before do
280
- builder = Caricature::ExpectationBuilder.new :some_method
281
- builder.pass_block do
282
- [1,3,4]
283
- end
284
- @expectation = builder.build
285
- end
286
-
287
- it "should have a block callback" do
288
- @expectation.should.has_block_callback
289
- end
290
-
291
- it "should execute the block with the result of the provided callback when executed" do
292
- ags = []
293
- @expectation.execute do |*args|
294
- ags = args
295
- end
296
- ags.should == [1,3,4]
297
- end
298
-
299
- end
300
-
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "Caricature::Expectations" do
4
+
5
+ end
6
+
7
+ describe "Caricature::ExpectationBuilder" do
8
+
9
+ it "should create an expectation builder" do
10
+ builder = Caricature::ExpectationBuilder.new :some_method
11
+ builder.should.not.equal nil
12
+ end
13
+
14
+ describe "when using all defaults" do
15
+
16
+ before do
17
+ builder = Caricature::ExpectationBuilder.new :some_method
18
+ @expectation = builder.build
19
+ end
20
+
21
+ it "should have the correct method_name" do
22
+ @expectation.method_name.should.equal :some_method
23
+ end
24
+
25
+ it "should have empty args" do
26
+ @expectation.args.should.be.empty?
27
+ end
28
+
29
+ it "should have no super call" do
30
+ @expectation.super.should.equal nil
31
+ end
32
+
33
+ it "should have no error args" do
34
+ @expectation.error_args.should.equal nil
35
+ end
36
+
37
+ it "should have no return_value" do
38
+ @expectation.return_value.should.equal nil
39
+ end
40
+
41
+ it "should have no callback" do
42
+ @expectation.should.not.has_callback?
43
+ end
44
+
45
+ end
46
+
47
+ describe "when specifying only arguments" do
48
+
49
+ before do
50
+ builder = Caricature::ExpectationBuilder.new :some_method
51
+ builder.with(1, 2, 3)
52
+ @expectation = builder.build
53
+ end
54
+
55
+ it "should have the correct method_name" do
56
+ @expectation.method_name.should.equal :some_method
57
+ end
58
+
59
+ it "should have empty args" do
60
+ @expectation.args.should.equal [1,2,3]
61
+ end
62
+
63
+ it "should have no super call" do
64
+ @expectation.super.should.equal nil
65
+ end
66
+
67
+ it "should have no error args" do
68
+ @expectation.error_args.should.equal nil
69
+ end
70
+
71
+ it "should have no return_value" do
72
+ @expectation.return_value.should.equal nil
73
+ end
74
+
75
+ it "should have no callback" do
76
+ @expectation.should.not.has_callback?
77
+ end
78
+
79
+ end
80
+
81
+ describe "when specifying only a block for the return value" do
82
+
83
+ before do
84
+ builder = Caricature::ExpectationBuilder.new :some_method
85
+ builder.return { 5 }
86
+ @expectation = builder.build
87
+ end
88
+
89
+ it "should have the correct method_name" do
90
+ @expectation.method_name.should.equal :some_method
91
+ end
92
+
93
+ it "should have empty args" do
94
+ @expectation.args.should.be.empty?
95
+ end
96
+
97
+ it "should have no super call" do
98
+ @expectation.super.should.equal nil
99
+ end
100
+
101
+ it "should have no error args" do
102
+ @expectation.error_args.should.equal nil
103
+ end
104
+
105
+ it "should have a return callback" do
106
+ @expectation.return_callback.should.not.be.nil
107
+ end
108
+
109
+ it "should have the correct return_value" do
110
+ @expectation.return_callback.call.should.equal 5
111
+ end
112
+
113
+ end
114
+
115
+ describe "when specifying a return value" do
116
+
117
+ before do
118
+ builder = Caricature::ExpectationBuilder.new :some_method
119
+ builder.return 5
120
+ @expectation = builder.build
121
+ end
122
+
123
+ it "should have the correct method_name" do
124
+ @expectation.method_name.should.equal :some_method
125
+ end
126
+
127
+ it "should have empty args" do
128
+ @expectation.args.should.be.empty?
129
+ end
130
+
131
+ it "should have no super call" do
132
+ @expectation.super.should.equal nil
133
+ end
134
+
135
+ it "should have no error args" do
136
+ @expectation.error_args.should.equal nil
137
+ end
138
+
139
+ it "should have the correct return_value" do
140
+ @expectation.return_value.should.equal 5
141
+ end
142
+
143
+ end
144
+
145
+ describe "when specifying a raise arguments" do
146
+
147
+ before do
148
+ @msg = "Hold on, that wasn't supposed to happen"
149
+ builder = Caricature::ExpectationBuilder.new :some_method
150
+ builder.raise @msg
151
+ @expectation = builder.build
152
+ end
153
+
154
+ it "should have the correct method_name" do
155
+ @expectation.method_name.should.equal :some_method
156
+ end
157
+
158
+ it "should have empty args" do
159
+ @expectation.args.should.be.empty?
160
+ end
161
+
162
+ it "should have no super call" do
163
+ @expectation.super.should.equal nil
164
+ end
165
+
166
+ it "should have no error args" do
167
+ @expectation.error_args.should.equal [@msg]
168
+ end
169
+
170
+ it "should have the correct return_value" do
171
+ @expectation.return_value.should.equal nil
172
+ end
173
+
174
+ end
175
+
176
+ describe "when specifying a return value and telling you want a call to super before" do
177
+
178
+ before do
179
+ builder = Caricature::ExpectationBuilder.new :some_method
180
+ builder.return(5).super_before
181
+ @expectation = builder.build
182
+ end
183
+
184
+ it "should have the correct method_name" do
185
+ @expectation.method_name.should.equal :some_method
186
+ end
187
+
188
+ it "should have empty args" do
189
+ @expectation.args.should.be.empty?
190
+ end
191
+
192
+ it "should have no super call" do
193
+ @expectation.super.should.equal :before
194
+ end
195
+
196
+ it "should have no error args" do
197
+ @expectation.error_args.should.equal nil
198
+ end
199
+
200
+ it "should have the correct return_value" do
201
+ @expectation.return_value.should.equal 5
202
+ end
203
+
204
+ end
205
+
206
+ describe "when giving a block to the arguments constraint it should register it as a callback" do
207
+
208
+ before do
209
+ builder = Caricature::ExpectationBuilder.new :some_method
210
+ @counter, @args = 0, []
211
+ builder.with(5) do |*ags|
212
+ @counter += 1
213
+ @args = ags
214
+ end
215
+ @expectation = builder.build
216
+ end
217
+
218
+ it "should have a callback" do
219
+ @expectation.should.has_callback?
220
+ end
221
+
222
+ it "should call the callback when the expectation is called" do
223
+ @expectation.execute
224
+ @counter.should == 1
225
+ end
226
+
227
+ it "should pass on the correct arguments" do
228
+ @expectation.execute 1, 2, 3
229
+ @args.should == [1, 2, 3]
230
+ end
231
+ end
232
+
233
+ describe "when giving a block to a super method it should register it" do
234
+
235
+ before do
236
+ builder = Caricature::ExpectationBuilder.new :some_method
237
+ @counter = 0
238
+ builder.super_after do
239
+ @counter += 1
240
+ end
241
+ @expectation = builder.build
242
+ end
243
+
244
+ it "should should have a callback" do
245
+ @expectation.block.should.not.be.nil
246
+ end
247
+
248
+ it "should pass on the correct callback" do
249
+ @expectation.block.call
250
+ @counter.should == 1
251
+ end
252
+
253
+ end
254
+
255
+ describe "when given arguments to the block pass method" do
256
+
257
+ before do
258
+ builder = Caricature::ExpectationBuilder.new :some_method
259
+ builder.pass_block(1,2,3)
260
+ @expectation = builder.build
261
+ end
262
+
263
+ it "should not have a block callback" do
264
+ @expectation.should.not.has_block_callback
265
+ end
266
+
267
+ it "should should execute the block with the provided arguments when executed" do
268
+ ags = []
269
+ @expectation.execute do |*args|
270
+ ags = args
271
+ end
272
+ ags.should == [1,2,3]
273
+ end
274
+
275
+ end
276
+
277
+ describe "when given arguments to the block pass method" do
278
+
279
+ before do
280
+ builder = Caricature::ExpectationBuilder.new :some_method
281
+ builder.pass_block do
282
+ [1,3,4]
283
+ end
284
+ @expectation = builder.build
285
+ end
286
+
287
+ it "should have a block callback" do
288
+ @expectation.should.has_block_callback
289
+ end
290
+
291
+ it "should execute the block with the result of the provided callback when executed" do
292
+ ags = []
293
+ @expectation.execute do |*args|
294
+ ags = args
295
+ end
296
+ ags.should == [1,3,4]
297
+ end
298
+
299
+ end
300
+
301
301
  end