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,254 +1,326 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "CLR to CLR interactions" do
4
-
5
- describe "when isolating CLR interfaces" do
6
- before do
7
- @ninja = ClrModels::Ninja.new
8
- @weapon = Caricature::Isolation.for(ClrModels::IWeapon)
9
- end
10
-
11
- it "should work without expectations" do
12
- @ninja.attack ClrModels::Ninja.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
- ninja = ClrModels::Ninja.new
19
- @weapon.when_receiving(:attack).with(ninja).return(5)
20
-
21
- @ninja.attack(ninja, @weapon).should.equal 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(ClrModels::Ninja.new).return(5)
28
-
29
- @ninja.attack(ClrModels::Ninja.new, @weapon).should.equal 0
30
- end
31
-
32
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
33
- ninja = ClrModels::Ninja.new
34
- @weapon.when_receiving(:attack).with(ninja).return(5)
35
-
36
- @ninja.attack(ninja, @weapon).should.equal 5
37
-
38
- @weapon.did_receive?(:attack).with(ninja).should.be.successful
39
- end
40
-
41
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
42
- ninja = ClrModels::Ninja.new
43
- @weapon.when_receiving(:attack).with(ninja).return(5)
44
-
45
- @ninja.attack(ninja, @weapon).should.equal 5
46
-
47
- @weapon.did_receive?(:attack).with(ClrModels::Ninja.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
- @ninja.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
- @ninja.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
- @ninja.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
- describe "plain vanilla CLR classes" do
76
- before do
77
- @weapon = ClrModels::Sword.new
78
- @ninja = Caricature::Isolation.for(ClrModels::Ninja)
79
- end
80
-
81
- it "should work without expectations" do
82
- result = @weapon.attack @ninja
83
- result.should.equal 0
84
-
85
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
86
- end
87
-
88
- it "should work for expectations with an argument constraint" do
89
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
90
-
91
- @weapon.attack(@ninja).should.equal 5
92
-
93
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
94
- end
95
-
96
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
97
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
98
-
99
- @weapon.attack(ClrModels::Ninja.new).should.equal 6
100
-
101
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
102
- end
103
-
104
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
105
- ninja = ClrModels::Ninja.new
106
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
107
-
108
- @weapon.attack(@ninja).should.equal 5
109
-
110
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
111
- end
112
-
113
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
114
- ninja = ClrModels::Ninja.new
115
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
116
-
117
- @weapon.attack(@ninja).should.equal 5
118
-
119
- @ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should.not.be.successful
120
- end
121
-
122
- it "should work with an expectation for any arguments" do
123
- @ninja.when_receiving(:survive_attack_with).return(5)
124
-
125
- result = @weapon.attack @ninja
126
- result.should.equal 5
127
-
128
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
129
- end
130
-
131
- it "should work with an assertion for specific arguments" do
132
- @ninja.when_receiving(:survive_attack_with) do |method_should|
133
- method_should.return(5)
134
- end
135
-
136
- result = @weapon.attack @ninja
137
- result.should.equal 5
138
-
139
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
140
- end
141
-
142
- it "should fail for an assertion with wrong arguments" do
143
- @ninja.when_receiving(:survive_attack_with) do |method_should|
144
- method_should.return(5)
145
- end
146
-
147
- result = @weapon.attack @ninja
148
- result.should.equal 5
149
-
150
- @ninja.
151
- did_receive?(:survive_attack_with).
152
- with(Caricature::Isolation.for(ClrModels::IWeapon)).
153
- should.not.be.successful
154
- end
155
-
156
- end
157
-
158
- describe "that have an indexer" do
159
- before do
160
- @cons = ClrModels::IndexerCaller.new
161
- @ind = Caricature::Isolation.for(ClrModels::IndexerContained)
162
- end
163
-
164
- it "should work without expectations" do
165
- @cons.call_index_on_class(@ind, "key1").should.be.nil
166
- end
167
-
168
-
169
- end
170
-
171
- end
172
-
173
- describe "when isolating CLR instances" do
174
-
175
- before do
176
- @weapon = ClrModels::Sword.new
177
- @ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
178
- end
179
-
180
- it "should work without expectations" do
181
- result = @weapon.attack @ninja
182
- result.should.equal 0
183
-
184
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
185
- end
186
-
187
- it "should work for expectations with an argument constraint" do
188
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
189
-
190
- @weapon.attack(@ninja).should.equal 5
191
-
192
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
193
- end
194
-
195
- it "should work for expectations with an argument constraint when a wrong argument is passed in" do
196
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
197
-
198
- @weapon.attack(ClrModels::Ninja.new).should.equal 6
199
-
200
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.not.be.successful
201
- end
202
-
203
- it "should work for expectations with an argument constraint and an assertion argument constraint" do
204
- ninja = ClrModels::Ninja.new
205
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
206
-
207
- @weapon.attack(@ninja).should.equal 5
208
-
209
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
210
- end
211
-
212
- it "should fail for expectations with an argument constraint and an assertion argument constraint" do
213
- ninja = ClrModels::Ninja.new
214
- @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
215
-
216
- @weapon.attack(@ninja).should.equal 5
217
-
218
- @ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should.not.be.successful
219
- end
220
-
221
- it "should work with an expectation for any arguments" do
222
- @ninja.when_receiving(:survive_attack_with).return(5)
223
-
224
- result = @weapon.attack @ninja
225
- result.should.equal 5
226
-
227
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
228
- end
229
-
230
- it "should fail for an assertion for specific arguments" do
231
- @ninja.when_receiving(:survive_attack_with) do |method_should|
232
- method_should.return(5)
233
- end
234
-
235
- result = @weapon.attack @ninja
236
- result.should.equal 5
237
- @ninja.did_receive?(:survive_attack_with).with(:any).should.be.successful
238
- @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
239
- end
240
-
241
- it "should allow to delegate the method call to the real instance (partial mock)" do
242
- @ninja.when_receiving(:survive_attack_with).super_after
243
-
244
- result = @weapon.attack @ninja
245
- result.should.equal 6
246
-
247
- @ninja.did_receive?(:survive_attack_with).should.be.successful
248
- end
249
-
250
-
251
-
252
- end
253
-
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ shared 'camel cased naming interceptions' do
4
+
5
+ it "should work without expectations" do
6
+ @ninja.attack ClrModels::Ninja.new, @weapon
7
+
8
+ @weapon.should.have_received?(:Attack)
9
+ end
10
+
11
+ it "should work for expectations with an argument constraint" do
12
+ ninja = ClrModels::Ninja.new
13
+ @weapon.when_receiving(:Attack).with(ninja).return(5)
14
+
15
+ @ninja.attack(ninja, @weapon).should.equal 5
16
+
17
+ @weapon.should.have_received?(:Attack) { |ver| ver.with(:any) }
18
+ end
19
+
20
+ it "should work for expectations with an argument constraint when a wrong argument is passed in" do
21
+ @weapon.when_receiving(:Attack).with(ClrModels::Ninja.new).return(5)
22
+
23
+ @ninja.attack(ClrModels::Ninja.new, @weapon).should.equal 0
24
+ end
25
+
26
+ it "should work for expectations with an argument constraint and an assertion argument constraint" do
27
+ ninja = ClrModels::Ninja.new
28
+ @weapon.when_receiving(:Attack).with(ninja).return(5)
29
+
30
+ @ninja.attack(ninja, @weapon).should.equal 5
31
+
32
+ @weapon.should.have_received?(:Attack) { |v| v.with(ninja) }
33
+ end
34
+
35
+ it "should fail for expectations with an argument constraint and an assertion argument constraint" do
36
+ ninja = ClrModels::Ninja.new
37
+ @weapon.when_receiving(:Attack).with(ninja).return(5)
38
+
39
+ @ninja.attack(ninja, @weapon).should.equal 5
40
+
41
+ @weapon.should.not.have_received?(:Attack){ |v| v.with(ClrModels::Ninja.new) }
42
+ end
43
+
44
+ it "should work with an expectation with any arguments" do
45
+ @weapon.when_receiving(:Damage).return(5)
46
+
47
+ @ninja.is_killed_by(@weapon).should.be.true?
48
+ @weapon.should.have_received?(:Damage)
49
+ end
50
+
51
+ it "should work with an expectation getting different method call result" do
52
+ @weapon.when_receiving(:Damage).return(2)
53
+
54
+ @ninja.is_killed_by(@weapon).should.be.false?
55
+ @weapon.should.have_received?(:Damage)
56
+ end
57
+
58
+ it "should work for an assertion on a specific argument" do
59
+ @weapon.when_receiving(:Damage).return(2)
60
+
61
+ @ninja.is_killed_by(@weapon).should.be.false?
62
+ @weapon.should.have_received?(:Damage)
63
+ end
64
+
65
+ end
66
+
67
+ describe "CLR to CLR interactions" do
68
+
69
+ describe "when using camel cased names" do
70
+
71
+ before do
72
+ @ninja = ClrModels::Ninja.new
73
+ @weapon = isolate ClrModels::IWeapon
74
+ end
75
+
76
+
77
+ behaves_like 'camel cased naming interceptions'
78
+
79
+ end
80
+
81
+ describe "when isolating CLR interfaces" do
82
+ before do
83
+ @ninja = ClrModels::Ninja.new
84
+ @weapon = isolate ClrModels::IWeapon
85
+ end
86
+
87
+ it "should work without expectations" do
88
+ @ninja.attack ClrModels::Ninja.new, @weapon
89
+
90
+ @weapon.should.have_received?(:attack)
91
+ end
92
+
93
+ it "should work for expectations with an argument constraint" do
94
+ ninja = ClrModels::Ninja.new
95
+ @weapon.when_receiving(:attack).with(ninja).return(5)
96
+
97
+ @ninja.attack(ninja, @weapon).should.equal 5
98
+
99
+ @weapon.should.have_received?(:attack) { |ver| ver.with(:any) }
100
+ end
101
+
102
+ it "should work for expectations with an argument constraint when a wrong argument is passed in" do
103
+ @weapon.when_receiving(:attack).with(ClrModels::Ninja.new).return(5)
104
+
105
+ @ninja.attack(ClrModels::Ninja.new, @weapon).should.equal 0
106
+ end
107
+
108
+ it "should work for expectations with an argument constraint and an assertion argument constraint" do
109
+ ninja = ClrModels::Ninja.new
110
+ @weapon.when_receiving(:attack).with(ninja).return(5)
111
+
112
+ @ninja.attack(ninja, @weapon).should.equal 5
113
+
114
+ @weapon.should.have_received?(:attack) { |v| v.with(ninja) }
115
+ end
116
+
117
+ it "should fail for expectations with an argument constraint and an assertion argument constraint" do
118
+ ninja = ClrModels::Ninja.new
119
+ @weapon.when_receiving(:attack).with(ninja).return(5)
120
+
121
+ @ninja.attack(ninja, @weapon).should.equal 5
122
+
123
+ @weapon.should.not.have_received?(:attack){ |v| v.with(ClrModels::Ninja.new) }
124
+ end
125
+
126
+ it "should work with an expectation with any arguments" do
127
+ @weapon.when_receiving(:damage).return(5)
128
+
129
+ @ninja.is_killed_by(@weapon).should.be.true?
130
+ @weapon.should.have_received?(:damage)
131
+ end
132
+
133
+ it "should work with an expectation getting different method call result" do
134
+ @weapon.when_receiving(:damage).return(2)
135
+
136
+ @ninja.is_killed_by(@weapon).should.be.false?
137
+ @weapon.should.have_received?(:damage)
138
+ end
139
+
140
+ it "should work for an assertion on a specific argument" do
141
+ @weapon.when_receiving(:damage).return(2)
142
+
143
+ @ninja.is_killed_by(@weapon).should.be.false?
144
+ @weapon.should.have_received?(:damage)
145
+ end
146
+
147
+ end
148
+
149
+ describe "when isolating CLR classes" do
150
+
151
+ describe "plain vanilla CLR classes" do
152
+ before do
153
+ @weapon = ClrModels::Sword.new
154
+ @ninja = isolate ClrModels::Ninja
155
+ end
156
+
157
+ it "should work without expectations" do
158
+ result = @weapon.attack @ninja
159
+ result.should.equal 0
160
+
161
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
162
+ end
163
+
164
+ it "should work for expectations with an argument constraint" do
165
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
166
+
167
+ @weapon.attack(@ninja).should.equal 5
168
+
169
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(:any) }
170
+ end
171
+
172
+ it "should work for expectations with an argument constraint when a wrong argument is passed in" do
173
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
174
+
175
+ @weapon.attack(ClrModels::Ninja.new).should.equal 6
176
+
177
+ @ninja.should.not.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
178
+ end
179
+
180
+ it "should work for expectations with an argument constraint and an assertion argument constraint" do
181
+ ninja = ClrModels::Ninja.new
182
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
183
+
184
+ @weapon.attack(@ninja).should.equal 5
185
+
186
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
187
+ end
188
+
189
+ it "should fail for expectations with an argument constraint and an assertion argument constraint" do
190
+ ninja = ClrModels::Ninja.new
191
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
192
+
193
+ @weapon.attack(@ninja).should.equal 5
194
+
195
+ @ninja.should.not.have_received?(:survive_attack_with) { |v| v.with(ClrModels::Sword.new) }
196
+ end
197
+
198
+ it "should work with an expectation for any arguments" do
199
+ @ninja.when_receiving(:survive_attack_with).return(5)
200
+
201
+ result = @weapon.attack @ninja
202
+ result.should.equal 5
203
+
204
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(:any) }
205
+ end
206
+
207
+ it "should work with an assertion for specific arguments" do
208
+ @ninja.when_receiving(:survive_attack_with) do |method_should|
209
+ method_should.return(5)
210
+ end
211
+
212
+ result = @weapon.attack @ninja
213
+ result.should.equal 5
214
+
215
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
216
+ end
217
+
218
+ it "should fail for an assertion with wrong arguments" do
219
+ @ninja.when_receiving(:survive_attack_with) do |method_should|
220
+ method_should.return(5)
221
+ end
222
+
223
+ result = @weapon.attack @ninja
224
+ result.should.equal 5
225
+
226
+ @ninja.should.not.have_received?(:survive_attack_with) {|v| v.with(isolate(ClrModels::IWeapon)) }
227
+ end
228
+
229
+ end
230
+
231
+ # describe "that have an indexer" do
232
+ # before do
233
+ # @cons = ClrModels::IndexerCaller.new
234
+ # @ind = Caricature::Isolation.for(ClrModels::IndexerContained)
235
+ # end
236
+ #
237
+ # it "should work without expectations" do
238
+ # @cons.call_index_on_class(@ind, "key1").should.be.nil
239
+ # end
240
+ #
241
+ #
242
+ # end
243
+
244
+ end
245
+
246
+ describe "when isolating CLR instances" do
247
+
248
+ before do
249
+ @weapon = ClrModels::Sword.new
250
+ @ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
251
+ end
252
+
253
+ it "should work without expectations" do
254
+ result = @weapon.attack @ninja
255
+ result.should.equal 0
256
+
257
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
258
+ end
259
+
260
+ it "should work for expectations with an argument constraint" do
261
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
262
+
263
+ @weapon.attack(@ninja).should.equal 5
264
+
265
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(:any) }
266
+ end
267
+
268
+ it "should work for expectations with an argument constraint when a wrong argument is passed in" do
269
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
270
+
271
+ @weapon.attack(ClrModels::Ninja.new).should.equal 6
272
+
273
+ @ninja.should.not.have_received?(:survive_attack_with){ |v| v.with(@weapon) }
274
+ end
275
+
276
+ it "should work for expectations with an argument constraint and an assertion argument constraint" do
277
+ ninja = ClrModels::Ninja.new
278
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
279
+
280
+ @weapon.attack(@ninja).should.equal 5
281
+
282
+ @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
283
+ end
284
+
285
+ it "should fail for expectations with an argument constraint and an assertion argument constraint" do
286
+ ninja = ClrModels::Ninja.new
287
+ @ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
288
+
289
+ @weapon.attack(@ninja).should.equal 5
290
+
291
+ @ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should.not.be.successful
292
+ end
293
+
294
+ it "should work with an expectation for any arguments" do
295
+ @ninja.when_receiving(:survive_attack_with).return(5)
296
+
297
+ result = @weapon.attack @ninja
298
+ result.should.equal 5
299
+
300
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(:any) }
301
+ end
302
+
303
+ it "should fail for an assertion for specific arguments" do
304
+ @ninja.when_receiving(:survive_attack_with) do |method_should|
305
+ method_should.return(5)
306
+ end
307
+
308
+ result = @weapon.attack @ninja
309
+ result.should.equal 5
310
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(:any) }
311
+ @ninja.should.have_received?(:survive_attack_with) { |v| v.with(@weapon) }
312
+ end
313
+
314
+ it "should allow to delegate the method call to the real instance (partial mock)" do
315
+ @ninja.when_receiving(:survive_attack_with).super_after
316
+
317
+ result = @weapon.attack @ninja
318
+ result.should.equal 6
319
+
320
+ @ninja.should.have_received?(:survive_attack_with)
321
+ end
322
+
323
+
324
+ end
325
+
254
326
  end