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,228 @@
1
+ require File.dirname(__FILE__) + "/../spec_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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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__) + "/../spec_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 == "5"
21
+ end
22
+
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,272 @@
1
+ require File.dirname(__FILE__) + "/../spec_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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 5
245
+ var = @soldier.did_receive?(:survive_attack_with).with(:any)
246
+ # @soldier.did_receive?(:survive_attack_with).with(@dagger).should be_successful
247
+ @soldier.should have_received(:survive_attack_with).with(@dagger)
248
+ end
249
+
250
+ it "should allow to delegate the method call to the real instance (partial mock)" do
251
+ @soldier.when_receiving(:survive_attack_with).super_after
252
+
253
+ result = @dagger.attack @soldier
254
+ result.should == 8
255
+
256
+ @soldier.should have_received(:survive_attack_with)
257
+ end
258
+
259
+ it "should be able to isolate objects with constructor params" do
260
+ sheath = Caricature::Isolation.for(Sheath)
261
+ sheath.when_receiving(:insert).raise("Overridden")
262
+ lambda { sheath.insert(@dagger) }.should raise_error(RuntimeError, /Overridden/)
263
+ end
264
+
265
+ it "should be able to isolate objects with constructor params" do
266
+ sheath = Caricature::Isolation.for(Sheath)
267
+ lambda { sheath.insert(@dagger) }.should_not raise_error
268
+ end
269
+
270
+ end
271
+
272
+ end