caricature 0.7.5 → 0.7.6

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.
Files changed (74) hide show
  1. data/README.rdoc +97 -97
  2. data/Rakefile +309 -310
  3. data/caricature.gemspec +123 -110
  4. data/lib/caricature/bacon/integration.rb +75 -75
  5. data/lib/caricature/bacon.rb +2 -2
  6. data/lib/caricature/clr/descriptor.rb +159 -159
  7. data/lib/caricature/clr/event_verification.rb +56 -56
  8. data/lib/caricature/clr/expectation.rb +100 -100
  9. data/lib/caricature/clr/isolation.rb +78 -78
  10. data/lib/caricature/clr/isolator.rb +252 -252
  11. data/lib/caricature/clr/messenger.rb +51 -49
  12. data/lib/caricature/clr/method_call_recorder.rb +96 -96
  13. data/lib/caricature/expectation.rb +1 -1
  14. data/lib/caricature/method_call_recorder.rb +3 -3
  15. data/lib/caricature/rspec/integration.rb +118 -118
  16. data/lib/caricature/version.rb +5 -5
  17. data/lib/caricature.rb +25 -25
  18. data/spec/bacon/integration/callback_spec.rb +156 -156
  19. data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
  20. data/spec/bacon/integration/event_spec.rb +97 -97
  21. data/spec/bacon/integration/indexer_spec.rb +27 -27
  22. data/spec/bacon/spec_helper.rb +4 -4
  23. data/spec/bacon/unit/descriptor_spec.rb +212 -212
  24. data/spec/bacon/unit/sword_spec.rb +39 -39
  25. data/spec/bacon/unit/verification_spec.rb +103 -103
  26. data/spec/bin/ClrModels.dll +0 -0
  27. data/spec/bin/ClrModels.dll.mdb +0 -0
  28. data/spec/fixtures/ExplodingCar.cs +56 -0
  29. data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
  30. data/spec/fixtures/ExposingWarrior.cs +58 -0
  31. data/spec/fixtures/IExplodingWarrior.cs +10 -0
  32. data/spec/fixtures/IExposing.cs +9 -0
  33. data/spec/fixtures/IExposingBridge.cs +9 -0
  34. data/spec/fixtures/IExposingWarrior.cs +8 -0
  35. data/spec/fixtures/IHaveAnIndexer.cs +8 -0
  36. data/spec/fixtures/IWarrior.cs +13 -0
  37. data/spec/fixtures/IWeapon.cs +9 -0
  38. data/spec/fixtures/IndexerCaller.cs +17 -0
  39. data/spec/fixtures/IndexerContained.cs +20 -0
  40. data/spec/fixtures/MyClassWithAStatic.cs +16 -0
  41. data/spec/fixtures/Ninja.cs +34 -0
  42. data/spec/fixtures/Samurai.cs +29 -0
  43. data/spec/fixtures/StaticCaller.cs +12 -0
  44. data/spec/fixtures/Sword.cs +16 -0
  45. data/spec/fixtures/SwordWithStatics.cs +19 -0
  46. data/spec/fixtures/clr_interaction.rb +61 -0
  47. data/spec/fixtures/dagger.rb +11 -0
  48. data/spec/fixtures/dagger_with_class_members.rb +11 -0
  49. data/spec/fixtures/sheath.rb +19 -0
  50. data/spec/fixtures/soldier.rb +29 -0
  51. data/spec/fixtures/soldier_with_class_members.rb +7 -0
  52. data/spec/fixtures/swift_cleanup_crew.rb +21 -0
  53. data/spec/fixtures/with_class_methods.rb +11 -0
  54. data/spec/{models → models.notused}/ClrModels.cs +241 -241
  55. data/spec/{models → models.notused}/ruby_models.rb +150 -150
  56. data/spec/rspec/integration/callback_spec.rb +156 -156
  57. data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
  58. data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
  59. data/spec/rspec/integration/indexer_spec.rb +27 -27
  60. data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
  61. data/spec/rspec/spec_helper.rb +12 -12
  62. data/spec/rspec/unit/core_ext_spec.rb +87 -87
  63. data/spec/rspec/unit/descriptor_spec.rb +210 -210
  64. data/spec/rspec/unit/event_spec.rb +16 -16
  65. data/spec/rspec/unit/expectation_spec.rb +300 -300
  66. data/spec/rspec/unit/interop_spec.rb +29 -29
  67. data/spec/rspec/unit/isolation_spec.rb +86 -86
  68. data/spec/rspec/unit/isolator_spec.rb +219 -219
  69. data/spec/rspec/unit/messaging_spec.rb +310 -310
  70. data/spec/rspec/unit/method_call_spec.rb +342 -342
  71. data/spec/rspec/unit/sword_spec.rb +39 -39
  72. data/spec/rspec/unit/verification_spec.rb +103 -103
  73. data/spec/spec_helper.rb +16 -15
  74. metadata +42 -11
@@ -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 == 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 be_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 be_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 == 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 == 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 be_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 be_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 == 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 == 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 be_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 be_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 == 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 be_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 be_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 == 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 == 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 be_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 be_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 == 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 == 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 be_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 be_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