caricature 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +97 -97
- data/Rakefile +309 -310
- data/caricature.gemspec +123 -110
- data/lib/caricature/bacon/integration.rb +75 -75
- data/lib/caricature/bacon.rb +2 -2
- data/lib/caricature/clr/descriptor.rb +159 -159
- data/lib/caricature/clr/event_verification.rb +56 -56
- data/lib/caricature/clr/expectation.rb +100 -100
- data/lib/caricature/clr/isolation.rb +78 -78
- data/lib/caricature/clr/isolator.rb +252 -252
- data/lib/caricature/clr/messenger.rb +51 -49
- data/lib/caricature/clr/method_call_recorder.rb +96 -96
- data/lib/caricature/expectation.rb +1 -1
- data/lib/caricature/method_call_recorder.rb +3 -3
- data/lib/caricature/rspec/integration.rb +118 -118
- data/lib/caricature/version.rb +5 -5
- data/lib/caricature.rb +25 -25
- data/spec/bacon/integration/callback_spec.rb +156 -156
- data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
- data/spec/bacon/integration/event_spec.rb +97 -97
- data/spec/bacon/integration/indexer_spec.rb +27 -27
- data/spec/bacon/spec_helper.rb +4 -4
- data/spec/bacon/unit/descriptor_spec.rb +212 -212
- data/spec/bacon/unit/sword_spec.rb +39 -39
- data/spec/bacon/unit/verification_spec.rb +103 -103
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/fixtures/ExplodingCar.cs +56 -0
- data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
- data/spec/fixtures/ExposingWarrior.cs +58 -0
- data/spec/fixtures/IExplodingWarrior.cs +10 -0
- data/spec/fixtures/IExposing.cs +9 -0
- data/spec/fixtures/IExposingBridge.cs +9 -0
- data/spec/fixtures/IExposingWarrior.cs +8 -0
- data/spec/fixtures/IHaveAnIndexer.cs +8 -0
- data/spec/fixtures/IWarrior.cs +13 -0
- data/spec/fixtures/IWeapon.cs +9 -0
- data/spec/fixtures/IndexerCaller.cs +17 -0
- data/spec/fixtures/IndexerContained.cs +20 -0
- data/spec/fixtures/MyClassWithAStatic.cs +16 -0
- data/spec/fixtures/Ninja.cs +34 -0
- data/spec/fixtures/Samurai.cs +29 -0
- data/spec/fixtures/StaticCaller.cs +12 -0
- data/spec/fixtures/Sword.cs +16 -0
- data/spec/fixtures/SwordWithStatics.cs +19 -0
- data/spec/fixtures/clr_interaction.rb +61 -0
- data/spec/fixtures/dagger.rb +11 -0
- data/spec/fixtures/dagger_with_class_members.rb +11 -0
- data/spec/fixtures/sheath.rb +19 -0
- data/spec/fixtures/soldier.rb +29 -0
- data/spec/fixtures/soldier_with_class_members.rb +7 -0
- data/spec/fixtures/swift_cleanup_crew.rb +21 -0
- data/spec/fixtures/with_class_methods.rb +11 -0
- data/spec/{models → models.notused}/ClrModels.cs +241 -241
- data/spec/{models → models.notused}/ruby_models.rb +150 -150
- data/spec/rspec/integration/callback_spec.rb +156 -156
- data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
- data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/rspec/integration/indexer_spec.rb +27 -27
- data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
- data/spec/rspec/spec_helper.rb +12 -12
- data/spec/rspec/unit/core_ext_spec.rb +87 -87
- data/spec/rspec/unit/descriptor_spec.rb +210 -210
- data/spec/rspec/unit/event_spec.rb +16 -16
- data/spec/rspec/unit/expectation_spec.rb +300 -300
- data/spec/rspec/unit/interop_spec.rb +29 -29
- data/spec/rspec/unit/isolation_spec.rb +86 -86
- data/spec/rspec/unit/isolator_spec.rb +219 -219
- data/spec/rspec/unit/messaging_spec.rb +310 -310
- data/spec/rspec/unit/method_call_spec.rb +342 -342
- data/spec/rspec/unit/sword_spec.rb +39 -39
- data/spec/rspec/unit/verification_spec.rb +103 -103
- data/spec/spec_helper.rb +16 -15
- metadata +42 -11
@@ -1,213 +1,213 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "Caricature::TypeDescriptor" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@des = Caricature::TypeDescriptor.new :in_unit_test_for_class
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should have a class_members method" do
|
10
|
-
@des.should.respond_to?(:class_members)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return an empty collection for the class members" do
|
14
|
-
@des.class_members.should.be.empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have an instance members method" do
|
18
|
-
@des.should.respond_to?(:instance_members)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return an empty collection for the instance members" do
|
22
|
-
@des.instance_members.should.be.empty
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should raise a NotImplementedError for the initialize_instance_members method" do
|
26
|
-
lambda { @des.initialize_instance_members_for Soldier }.should.raise NotImplementedError
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should raise a NotImplementedError for the initialize_class_members method" do
|
30
|
-
lambda { @des.initialize_class_members_for Soldier }.should.raise NotImplementedError
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "Caricature::MemberDescriptor" do
|
36
|
-
|
37
|
-
it "should have a name" do
|
38
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
39
|
-
des.name.should.not.be.nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should have the correct name" do
|
43
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
44
|
-
des.name.should.equal 'a name'
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should have a return_type" do
|
48
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
49
|
-
des.return_type.should.not.be.nil
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should have the correct return_type" do
|
53
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
54
|
-
des.return_type.should.equal 'a type'
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should say it's an instance type" do
|
58
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
59
|
-
des.should.be.instance_member
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should say it's not an instance type" do
|
63
|
-
des = Caricature::MemberDescriptor.new 'a name', 'a type', false
|
64
|
-
des.should.not.be.instance_member
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
describe Caricature::ClrEventDescriptor.to_s do
|
70
|
-
|
71
|
-
it "should have an event name" do
|
72
|
-
des = Caricature::ClrEventDescriptor.new "EventName"
|
73
|
-
des.event_name.should == "EventName"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should correctly identify when it's not an instance member" do
|
77
|
-
des = Caricature::ClrEventDescriptor.new "EventName", false
|
78
|
-
des.should.not.be.instance_member
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "Caricature::ClrInterfaceDescriptor" do
|
84
|
-
|
85
|
-
describe "when collecting methods" do
|
86
|
-
|
87
|
-
before do
|
88
|
-
@des = Caricature::ClrInterfaceDescriptor.new ClrModels::IWeapon
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should have 2 instance members" do
|
92
|
-
@des.instance_members.size.should.equal 2
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should contain only instance members" do
|
96
|
-
result = true
|
97
|
-
@des.instance_members.each do |mem|
|
98
|
-
result = false unless mem.instance_member?
|
99
|
-
end
|
100
|
-
|
101
|
-
result.should.be.true
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should have a damage instance member" do
|
105
|
-
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should correctly identify indexers" do
|
109
|
-
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
110
|
-
des.instance_members.select { |mem| mem.name == "get_Item" }.should.not.be.empty
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should correctly identify indexers" do
|
114
|
-
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
115
|
-
des.instance_members.select { |mem| mem.name == "set_Item" }.should.not.be.empty
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "when collecting events" do
|
120
|
-
|
121
|
-
before do
|
122
|
-
@des = Caricature::ClrInterfaceDescriptor.new ClrModels::IExplodingWarrior
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should have collected 2 events" do
|
126
|
-
@des.events.size.should == 2
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should have collected 2 instance events" do
|
130
|
-
@des.events.all? { |ev| ev.instance_member? }.should.be.true?
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
describe "Caricature::ClrClassDescriptor" do
|
139
|
-
|
140
|
-
describe "when collecting methods" do
|
141
|
-
|
142
|
-
before do
|
143
|
-
@des = Caricature::ClrClassDescriptor.new ClrModels::SwordWithStatics
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should have 11 instance members" do
|
147
|
-
@des.instance_members.size.should.equal 11
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should have 5 static members" do
|
151
|
-
@des.class_members.size.should.equal 5
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should have a damage instance member" do
|
155
|
-
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should have a another method instance member" do
|
159
|
-
@des.instance_members.select { |mem| mem.name == "another_method" }.should.not.be.empty
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should correctly identify indexers" do
|
163
|
-
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
164
|
-
des.instance_members.select { |mem| mem.name == "get_Item" }.should.not.be.empty
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should correctly identify indexers" do
|
168
|
-
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
169
|
-
des.instance_members.select { |mem| mem.name == "set_Item" }.should.not.be.empty
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "when collecting events" do
|
174
|
-
|
175
|
-
before do
|
176
|
-
@des = Caricature::ClrClassDescriptor.new ClrModels::ExposingWarrior
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should have 2 instance events" do
|
180
|
-
@des.events.size.should == 2
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should should have 1 class event" do
|
184
|
-
@des.class_events.size.should == 1
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "Caricature::RubyObjectDescriptor" do
|
192
|
-
|
193
|
-
before do
|
194
|
-
@des = Caricature::RubyObjectDescriptor.new DaggerWithClassMembers
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should have 2 instance members" do
|
198
|
-
@des.instance_members.size.should.equal 2
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should have a damage instance member" do
|
202
|
-
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should have 1 class member" do
|
206
|
-
@des.class_members.size.should.equal 1
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should have a class_name class member" do
|
210
|
-
@des.class_members.select { |mem| mem.name == "class_name" }.should.not.be.empty
|
211
|
-
end
|
212
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "Caricature::TypeDescriptor" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@des = Caricature::TypeDescriptor.new :in_unit_test_for_class
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a class_members method" do
|
10
|
+
@des.should.respond_to?(:class_members)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return an empty collection for the class members" do
|
14
|
+
@des.class_members.should.be.empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have an instance members method" do
|
18
|
+
@des.should.respond_to?(:instance_members)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return an empty collection for the instance members" do
|
22
|
+
@des.instance_members.should.be.empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise a NotImplementedError for the initialize_instance_members method" do
|
26
|
+
lambda { @des.initialize_instance_members_for Soldier }.should.raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise a NotImplementedError for the initialize_class_members method" do
|
30
|
+
lambda { @des.initialize_class_members_for Soldier }.should.raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Caricature::MemberDescriptor" do
|
36
|
+
|
37
|
+
it "should have a name" do
|
38
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
39
|
+
des.name.should.not.be.nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have the correct name" do
|
43
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
44
|
+
des.name.should.equal 'a name'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a return_type" do
|
48
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
49
|
+
des.return_type.should.not.be.nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have the correct return_type" do
|
53
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
54
|
+
des.return_type.should.equal 'a type'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should say it's an instance type" do
|
58
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type'
|
59
|
+
des.should.be.instance_member
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should say it's not an instance type" do
|
63
|
+
des = Caricature::MemberDescriptor.new 'a name', 'a type', false
|
64
|
+
des.should.not.be.instance_member
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe Caricature::ClrEventDescriptor.to_s do
|
70
|
+
|
71
|
+
it "should have an event name" do
|
72
|
+
des = Caricature::ClrEventDescriptor.new "EventName"
|
73
|
+
des.event_name.should == "EventName"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should correctly identify when it's not an instance member" do
|
77
|
+
des = Caricature::ClrEventDescriptor.new "EventName", false
|
78
|
+
des.should.not.be.instance_member
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "Caricature::ClrInterfaceDescriptor" do
|
84
|
+
|
85
|
+
describe "when collecting methods" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
@des = Caricature::ClrInterfaceDescriptor.new ClrModels::IWeapon
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should have 2 instance members" do
|
92
|
+
@des.instance_members.size.should.equal 2
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should contain only instance members" do
|
96
|
+
result = true
|
97
|
+
@des.instance_members.each do |mem|
|
98
|
+
result = false unless mem.instance_member?
|
99
|
+
end
|
100
|
+
|
101
|
+
result.should.be.true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have a damage instance member" do
|
105
|
+
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should correctly identify indexers" do
|
109
|
+
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
110
|
+
des.instance_members.select { |mem| mem.name == "get_Item" }.should.not.be.empty
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should correctly identify indexers" do
|
114
|
+
des = Caricature::ClrInterfaceDescriptor.new ClrModels::IHaveAnIndexer
|
115
|
+
des.instance_members.select { |mem| mem.name == "set_Item" }.should.not.be.empty
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "when collecting events" do
|
120
|
+
|
121
|
+
before do
|
122
|
+
@des = Caricature::ClrInterfaceDescriptor.new ClrModels::IExplodingWarrior
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have collected 2 events" do
|
126
|
+
@des.events.size.should == 2
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have collected 2 instance events" do
|
130
|
+
@des.events.all? { |ev| ev.instance_member? }.should.be.true?
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "Caricature::ClrClassDescriptor" do
|
139
|
+
|
140
|
+
describe "when collecting methods" do
|
141
|
+
|
142
|
+
before do
|
143
|
+
@des = Caricature::ClrClassDescriptor.new ClrModels::SwordWithStatics
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have 11 instance members" do
|
147
|
+
@des.instance_members.size.should.equal 11
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should have 5 static members" do
|
151
|
+
@des.class_members.size.should.equal 5
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should have a damage instance member" do
|
155
|
+
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should have a another method instance member" do
|
159
|
+
@des.instance_members.select { |mem| mem.name == "another_method" }.should.not.be.empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should correctly identify indexers" do
|
163
|
+
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
164
|
+
des.instance_members.select { |mem| mem.name == "get_Item" }.should.not.be.empty
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should correctly identify indexers" do
|
168
|
+
des = Caricature::ClrClassDescriptor.new ClrModels::IndexerContained
|
169
|
+
des.instance_members.select { |mem| mem.name == "set_Item" }.should.not.be.empty
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "when collecting events" do
|
174
|
+
|
175
|
+
before do
|
176
|
+
@des = Caricature::ClrClassDescriptor.new ClrModels::ExposingWarrior
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should have 2 instance events" do
|
180
|
+
@des.events.size.should == 2
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should should have 1 class event" do
|
184
|
+
@des.class_events.size.should == 1
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "Caricature::RubyObjectDescriptor" do
|
192
|
+
|
193
|
+
before do
|
194
|
+
@des = Caricature::RubyObjectDescriptor.new DaggerWithClassMembers
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should have 2 instance members" do
|
198
|
+
@des.instance_members.size.should.equal 2
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should have a damage instance member" do
|
202
|
+
@des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should have 1 class member" do
|
206
|
+
@des.class_members.size.should.equal 1
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should have a class_name class member" do
|
210
|
+
@des.class_members.select { |mem| mem.name == "class_name" }.should.not.be.empty
|
211
|
+
end
|
212
|
+
|
213
213
|
end
|
@@ -1,40 +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.equal 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.equal 5
|
35
|
-
sword2.attack(@warrior).should.equal 15
|
36
|
-
|
37
|
-
@warrior.did_receive?(:survive_attack_with).with(sword2).should.be.successful
|
38
|
-
end
|
39
|
-
|
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.equal 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.equal 5
|
35
|
+
sword2.attack(@warrior).should.equal 15
|
36
|
+
|
37
|
+
@warrior.did_receive?(:survive_attack_with).with(sword2).should.be.successful
|
38
|
+
end
|
39
|
+
|
40
40
|
end
|