caricature 0.7.1 → 0.7.2

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 (50) hide show
  1. data/Rakefile +47 -40
  2. data/caricature.gemspec +50 -17
  3. data/lib/caricature.rb +9 -1
  4. data/lib/caricature/bacon/integration.rb +3 -5
  5. data/lib/caricature/clr/isolation.rb +1 -1
  6. data/lib/caricature/method_call_recorder.rb +7 -2
  7. data/lib/caricature/rspec.rb +1 -0
  8. data/lib/caricature/rspec/integration.rb +77 -0
  9. data/lib/caricature/verification.rb +9 -1
  10. data/lib/caricature/version.rb +1 -1
  11. data/lib/core_ext/class.rb +1 -1
  12. data/lib/core_ext/module.rb +1 -1
  13. data/lib/core_ext/object.rb +2 -2
  14. data/spec/{integration → bacon/integration}/callback_spec.rb +1 -1
  15. data/spec/{integration → bacon/integration}/clr_to_clr_spec.rb +1 -1
  16. data/spec/{integration → bacon/integration}/clr_to_ruby_spec.rb +1 -1
  17. data/spec/{integration → bacon/integration}/indexer_spec.rb +1 -1
  18. data/spec/{integration → bacon/integration}/ruby_to_ruby_spec.rb +1 -1
  19. data/spec/bacon/spec_helper.rb +5 -0
  20. data/spec/{unit → bacon/unit}/core_ext_spec.rb +13 -13
  21. data/spec/{unit → bacon/unit}/descriptor_spec.rb +1 -1
  22. data/spec/{unit → bacon/unit}/expectation_spec.rb +1 -1
  23. data/spec/{unit → bacon/unit}/interop_spec.rb +3 -3
  24. data/spec/{unit → bacon/unit}/isolation_spec.rb +1 -1
  25. data/spec/{unit → bacon/unit}/isolator_spec.rb +1 -1
  26. data/spec/{unit → bacon/unit}/messaging_spec.rb +1 -1
  27. data/spec/{unit → bacon/unit}/method_call_spec.rb +2 -2
  28. data/spec/{unit → bacon/unit}/sword_spec.rb +1 -1
  29. data/spec/{unit → bacon/unit}/verification_spec.rb +1 -1
  30. data/spec/bin/ClrModels.dll +0 -0
  31. data/spec/bin/ClrModels.dll.mdb +0 -0
  32. data/spec/{bacon_helper.rb → models/ruby_models.rb} +9 -26
  33. data/spec/rspec/integration/callback_spec.rb +157 -0
  34. data/spec/rspec/integration/clr_to_clr_spec.rb +255 -0
  35. data/spec/rspec/integration/clr_to_ruby_spec.rb +228 -0
  36. data/spec/rspec/integration/indexer_spec.rb +28 -0
  37. data/spec/rspec/integration/ruby_to_ruby_spec.rb +272 -0
  38. data/spec/rspec/spec_helper.rb +6 -0
  39. data/spec/rspec/unit/core_ext_spec.rb +87 -0
  40. data/spec/rspec/unit/descriptor_spec.rb +160 -0
  41. data/spec/rspec/unit/expectation_spec.rb +301 -0
  42. data/spec/rspec/unit/interop_spec.rb +43 -0
  43. data/spec/rspec/unit/isolation_spec.rb +87 -0
  44. data/spec/rspec/unit/isolator_spec.rb +220 -0
  45. data/spec/rspec/unit/messaging_spec.rb +311 -0
  46. data/spec/rspec/unit/method_call_spec.rb +343 -0
  47. data/spec/rspec/unit/sword_spec.rb +40 -0
  48. data/spec/rspec/unit/verification_spec.rb +104 -0
  49. data/spec/spec_helper.rb +15 -0
  50. metadata +37 -18
@@ -0,0 +1,343 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "MethodCallRecorder" do
4
+
5
+ before do
6
+ @recorder = Caricature::MethodCallRecorder.new
7
+ end
8
+
9
+ describe "when recording a call without arguments" do
10
+
11
+ before do
12
+ @recorder.record_call :my_method
13
+ end
14
+
15
+ it "should have 1 method call" do
16
+ @recorder.method_calls[:instance].size.should == 1
17
+ end
18
+
19
+ describe "recorded call" do
20
+
21
+ before do
22
+ @mc = @recorder.method_calls[:instance][:my_method]
23
+ end
24
+
25
+ it "should have a method call collected" do
26
+ @mc.should_not be_nil
27
+ end
28
+
29
+ it "should have the correct name" do
30
+ @mc.method_name.should == :my_method
31
+ end
32
+
33
+ it "should have no arguments" do
34
+ @mc.args.should == [Caricature::ArgumentRecording.new]
35
+ end
36
+
37
+ it "should have no block" do
38
+ @mc.block.should be_nil
39
+ end
40
+
41
+ it "should have a count a 1" do
42
+ @mc.count.should == 1
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ describe "when recording a call without arguments but with a block" do
50
+
51
+ before do
52
+ @block_content = "I'm in the block"
53
+ @recorder.record_call :my_method do
54
+ @block_content
55
+ end
56
+ end
57
+
58
+ it "should have 1 method call" do
59
+ @recorder.method_calls[:instance].size.should == 1
60
+ end
61
+
62
+ describe "recorded call" do
63
+
64
+ before do
65
+ @mc = @recorder.method_calls[:instance][:my_method]
66
+ end
67
+
68
+ it "should have a method call collected" do
69
+ @mc.should_not be_nil
70
+ end
71
+
72
+ it "should have the correct name" do
73
+ @mc.method_name.should == :my_method
74
+ end
75
+
76
+ it "should have no arguments" do
77
+ @mc.args.should == [Caricature::ArgumentRecording.new]
78
+ end
79
+
80
+ it "should have a block" do
81
+ @mc.args.first.block.should_not be_nil
82
+ end
83
+
84
+ it "should have the correct block" do
85
+ @mc.args.first.block.call.should == @block_content
86
+ end
87
+
88
+ it "should have a count a 1" do
89
+ @mc.count.should == 1
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ describe "when recording a call 1 argument" do
97
+
98
+ before do
99
+ @recorder.record_call :my_method, :instance, nil, 1
100
+ end
101
+
102
+ it "should have 1 method call" do
103
+ @recorder.method_calls[:instance].size.should == 1
104
+ end
105
+
106
+ describe "recorded call" do
107
+
108
+ before do
109
+ @mc = @recorder.method_calls[:instance][:my_method]
110
+ end
111
+
112
+ it "should have a method call collected" do
113
+ @mc.should_not be_nil
114
+ end
115
+
116
+ it "should have the correct name" do
117
+ @mc.method_name.should == :my_method
118
+ end
119
+
120
+ it "should have 1 argument" do
121
+ @mc.args.size.should == 1
122
+ end
123
+
124
+ it "should have the correct argument" do
125
+ @mc.args.should == [Caricature::ArgumentRecording.new([1])]
126
+ end
127
+
128
+ it "should have no block" do
129
+ @mc.block.should be_nil
130
+ end
131
+
132
+ it "should have a count a 1" do
133
+ @mc.count.should == 1
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+ describe "when recording a call 2 arguments" do
141
+
142
+ before do
143
+ @recorder.record_call :my_method, :instance, nil, 1, 2
144
+ end
145
+
146
+ it "should have 1 method call" do
147
+ @recorder.method_calls[:instance].size.should == 1
148
+ end
149
+
150
+ describe "recorded call" do
151
+
152
+ before do
153
+ @mc = @recorder.method_calls[:instance][:my_method]
154
+ end
155
+
156
+ it "should have a method call collected" do
157
+ @mc.should_not be_nil
158
+ end
159
+
160
+ it "should have the correct name" do
161
+ @mc.method_name.should == :my_method
162
+ end
163
+
164
+ it "should have 1 argument recording" do
165
+ @mc.args.size.should == 1
166
+ end
167
+
168
+ it "should have the correct arguments" do
169
+ @mc.args.should == [Caricature::ArgumentRecording.new([1, 2])]
170
+ end
171
+
172
+ it "should have no block" do
173
+ @mc.block.should be_nil
174
+ end
175
+
176
+ it "should have a count a 1" do
177
+ @mc.count.should == 1
178
+ end
179
+
180
+ end
181
+
182
+ end
183
+
184
+ describe "when recording 2 calls with no arguments" do
185
+
186
+ before do
187
+ @recorder.record_call :my_method
188
+ @recorder.record_call :my_method
189
+ end
190
+
191
+ it "should have 1 method call" do
192
+ @recorder.method_calls[:instance].size.should == 1
193
+ end
194
+
195
+ describe "recorded call" do
196
+
197
+ before do
198
+ @mc = @recorder.method_calls[:instance][:my_method]
199
+ end
200
+
201
+ it "should have a method call collected" do
202
+ @mc.should_not be_nil
203
+ end
204
+
205
+ it "should have the correct name" do
206
+ @mc.method_name.should == :my_method
207
+ end
208
+
209
+ it "should have no arguments" do
210
+ @mc.args.should == [Caricature::ArgumentRecording.new]
211
+ end
212
+
213
+ it "should have no block" do
214
+ @mc.block.should be_nil
215
+ end
216
+
217
+ it "should have a count of 2" do
218
+ @mc.count.should == 2
219
+ end
220
+
221
+ end
222
+
223
+ end
224
+
225
+ describe "when recording a call with a block" do
226
+ before do
227
+ @args = []
228
+ @b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
229
+ @args = args
230
+ end
231
+
232
+ end
233
+
234
+ it "should return a block" do
235
+ @b.should_not be_nil
236
+ end
237
+
238
+ it "should return a block that wraps a recording" do
239
+ @b.call 8, 9, 0
240
+ @recorder.method_calls[:instance][:some_method].args.first.blocks.first.args.should == [8, 9, 0]
241
+ end
242
+
243
+ it "should call the original block" do
244
+ @b.call 8, 9, 0
245
+ @args.should == [8, 9, 0]
246
+ end
247
+ end
248
+
249
+ describe "when recording 2 calls with different arguments" do
250
+
251
+ before do
252
+ @recorder.record_call :my_method
253
+ @recorder.record_call :my_method, :instance, nil, 1, 3, 4
254
+ end
255
+
256
+ it "should have 1 method call" do
257
+ @recorder.method_calls[:instance].size.should == 1
258
+ end
259
+
260
+ describe "recorded call" do
261
+
262
+ before do
263
+ @mc = @recorder.method_calls[:instance][:my_method]
264
+ end
265
+
266
+ it "should have a method call collected" do
267
+ @mc.should_not be_nil
268
+ end
269
+
270
+ it "should have the correct name" do
271
+ @mc.method_name.should == :my_method
272
+ end
273
+
274
+ it "should have argument variations" do
275
+ @mc.has_argument_variations?.should be_true
276
+ end
277
+
278
+ it "should have no block" do
279
+ @mc.block.should be_nil
280
+ end
281
+
282
+ it "should have a count of 2" do
283
+ @mc.count.should == 2
284
+ end
285
+
286
+ end
287
+
288
+ end
289
+
290
+ describe "when asked if a certain method was called" do
291
+
292
+ before do
293
+ @recorder.record_call :my_method
294
+ @recorder.record_call :my_method, :instance, nil, 1, 3, 4
295
+
296
+ end
297
+
298
+ it "should confirm when we don't care about the arguments" do
299
+ @recorder.was_called?(:my_method, nil, :instance, :any).should be_true
300
+ end
301
+
302
+ it "should confirm when there are no argument variations" do
303
+ @recorder.record_call :another_method
304
+ @recorder.was_called?(:another_method, nil, :instance, :any).should be_true
305
+ end
306
+
307
+ it "should be negative when we provide the wrong arguments" do
308
+ @recorder.was_called?(:my_method, nil, :instance, 1, 2, 5).should be_false
309
+ end
310
+
311
+ it "should be positive when we provide the correct arguments" do
312
+ @recorder.was_called?(:my_method, nil, :instance, 1, 3, 4).should be_true
313
+ end
314
+
315
+ it "should be positive when we provide no arguments and a call had been recorded without arguments" do
316
+ @recorder.was_called?(:my_method, nil, :instance).should be_true
317
+ end
318
+
319
+ describe "with block" do
320
+
321
+ before do
322
+ @args = []
323
+ b = @recorder.record_call :some_method, :instance, nil, 5, 6, 7 do |*args|
324
+ @args << args
325
+ end
326
+ b.call 1, 3, 5
327
+ b.call 3, 4, 6
328
+ b.call
329
+ end
330
+
331
+ it "should be positive when we provide any arguments" do
332
+ @recorder.was_called?(:some_method, [:any], :instance, :any).should be_true
333
+ end
334
+
335
+ it "should be positive when we provide specific arguments" do
336
+ @recorder.was_called?(:some_method, [1, 3, 5], :instance, :any).should be_true
337
+ end
338
+
339
+ end
340
+
341
+ end
342
+
343
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+
3
+ class ClrModels::Sword
4
+
5
+ def to_s
6
+ "<ClrModels::Sword object_id: #{object_id} >"
7
+ end
8
+ alias_method :inspect, :to_s
9
+
10
+ end
11
+
12
+ describe "ClrModels::Sword" do
13
+
14
+ before do
15
+ @warrior = Caricature::Isolation.for ClrModels::IWarrior
16
+ end
17
+
18
+ it "should call survive_attack on the mock" do
19
+ @warrior.when_receiving(:survive_attack_with).return(5)
20
+
21
+ sword = ClrModels::Sword.new
22
+ sword.attack(@warrior).should == 5
23
+
24
+ @warrior.did_receive?(:survive_attack_with).should be_successful
25
+ end
26
+
27
+ it "should return different results when expectation is defined with arguments" do
28
+ sword1 = ClrModels::Sword.new
29
+ sword2 = ClrModels::Sword.new
30
+
31
+ @warrior.when_receiving(:survive_attack_with).with(:any).return(5)
32
+ @warrior.when_receiving(:survive_attack_with).with(sword2).return(15)
33
+
34
+ sword1.attack(@warrior).should == 5
35
+ sword2.attack(@warrior).should == 15
36
+
37
+ @warrior.did_receive?(:survive_attack_with).with(sword2).should be_successful
38
+ end
39
+
40
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "Caricature::Verification" do
4
+
5
+ describe "Matching" do
6
+
7
+ before do
8
+ @rec = Caricature::MethodCallRecorder.new
9
+ @ver = Caricature::Verification.new(:my_method, @rec)
10
+ end
11
+
12
+ describe "Default initialisation" do
13
+
14
+ it "should allow any arguments" do
15
+ @ver.any_args?.should be_true
16
+ end
17
+
18
+ it "should match the provided method name when no arguments have been given" do
19
+ @ver.matches?(:my_method).should be_true
20
+ end
21
+
22
+ it "should match the method name when arguments have been given" do
23
+ @ver.matches?(:my_method, 1, 3, 4).should be_true
24
+ end
25
+
26
+ end
27
+
28
+ describe "when initialized with and constrained by arguments" do
29
+
30
+ before do
31
+ @ver.with(1, 3, 6)
32
+ end
33
+
34
+ it "should match the provided method name when the correct arguments are given" do
35
+ @ver.matches?(:my_method, 1, 3, 6).should be_true
36
+ end
37
+
38
+ it "should not match the method name when the arguments are not correct" do
39
+ @ver.matches?(:my_method, 1, 3, 3).should be_false
40
+ end
41
+
42
+ it "should not match the method name when no arguments have been given" do
43
+ @ver.matches?(:my_method).should be_false
44
+ end
45
+
46
+ end
47
+
48
+ describe "when initialized with and not constrained by arguments" do
49
+
50
+ before do
51
+ @ver.with(1, 3, 6).allow_any_arguments
52
+ end
53
+
54
+ it "should match the provided method name when the correct arguments are given" do
55
+ @ver.matches?(:my_method, 1, 3, 6).should be_true
56
+ end
57
+
58
+ it "should match the method name when the arguments are not correct" do
59
+ @ver.matches?(:my_method, 1, 3, 3).should be_true
60
+ end
61
+
62
+ it "should match the method name when no arguments have been given" do
63
+ @ver.matches?(:my_method).should be_true
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ describe "Verifying" do
71
+
72
+ before do
73
+ @rec = Caricature::MethodCallRecorder.new
74
+ @rec.record_call :my_method
75
+ @rec.record_call :my_method, :instance, nil, 1, 2, 3
76
+ @rec.record_call :another_method
77
+
78
+ end
79
+
80
+ it "should be successful with any arguments allowed" do
81
+ ver = Caricature::Verification.new(:my_method, @rec)
82
+ ver.should be_successful
83
+ end
84
+
85
+ it "should be successful with a correct set of arguments provided for my_method" do
86
+ ver = Caricature::Verification.new(:my_method, @rec)
87
+ ver.with 1, 2, 3
88
+ ver.should be_successful
89
+ end
90
+
91
+ it "should be unsuccessful when a wrong set of arguments is provided" do
92
+ ver = Caricature::Verification.new(:my_method, @rec)
93
+ ver.with 1, 5, 7
94
+ ver.should_not be_successful
95
+ end
96
+
97
+ it "should be unsuccessful when the wrong method name is provided" do
98
+ ver = Caricature::Verification.new(:some_method, @rec)
99
+ ver.should_not be_successful
100
+ end
101
+
102
+ end
103
+
104
+ end