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.
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
@@ -76,7 +76,7 @@ describe "CLR event handling" do
76
76
  describe "for CLR interfaces" do
77
77
 
78
78
  before do
79
- @proxy = isolate ClrModels::IExplodingWarrior
79
+ @proxy = isolation_for ClrModels::IExplodingWarrior
80
80
  @subscriber = ClrModels::ExposedChangedSubscriber.new(@proxy)
81
81
  end
82
82
 
@@ -87,7 +87,7 @@ describe "CLR event handling" do
87
87
  describe "for CLR classes" do
88
88
 
89
89
  before do
90
- @proxy = isolate ClrModels::ExposingWarrior
90
+ @proxy = isolation_for ClrModels::ExposingWarrior
91
91
  @subscriber = ClrModels::ExposedChangedSubscriber.new(@proxy)
92
92
  end
93
93
 
@@ -1,271 +1,271 @@
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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 5
245
- var = @soldier.did_receive?(:survive_attack_with).with(:any)
246
- @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
247
- end
248
-
249
- it "should allow to delegate the method call to the real instance (partial mock)" do
250
- @soldier.when_receiving(:survive_attack_with).super_after
251
-
252
- result = @dagger.attack @soldier
253
- result.should.equal 8
254
-
255
- @soldier.did_receive?(:survive_attack_with).should.be.successful
256
- end
257
-
258
- it "should be able to isolate objects with constructor params" do
259
- sheath = Caricature::Isolation.for(Sheath)
260
- sheath.when_receiving(:insert).raise("Overridden")
261
- lambda { sheath.insert(@dagger) }.should.raise.message.should.match(/Overridden/)
262
- end
263
-
264
- it "should be able to isolate objects with constructor params" do
265
- sheath = Caricature::Isolation.for(Sheath)
266
- lambda { sheath.insert(@dagger) }.should.not.raise
267
- end
268
-
269
- end
270
-
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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 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.equal 5
245
+ var = @soldier.did_receive?(:survive_attack_with).with(:any)
246
+ @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
247
+ end
248
+
249
+ it "should allow to delegate the method call to the real instance (partial mock)" do
250
+ @soldier.when_receiving(:survive_attack_with).super_after
251
+
252
+ result = @dagger.attack @soldier
253
+ result.should.equal 8
254
+
255
+ @soldier.did_receive?(:survive_attack_with).should.be.successful
256
+ end
257
+
258
+ it "should be able to isolate objects with constructor params" do
259
+ sheath = Caricature::Isolation.for(Sheath)
260
+ sheath.when_receiving(:insert).raise("Overridden")
261
+ lambda { sheath.insert(@dagger) }.should.raise.message.should.match(/Overridden/)
262
+ end
263
+
264
+ it "should be able to isolate objects with constructor params" do
265
+ sheath = Caricature::Isolation.for(Sheath)
266
+ lambda { sheath.insert(@dagger) }.should.not.raise
267
+ end
268
+
269
+ end
270
+
271
271
  end