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.
- 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,87 +1,87 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "Caricature::Isolation" do
|
4
|
-
|
5
|
-
describe "when creating an isolation for ruby objects" do
|
6
|
-
|
7
|
-
it "should not raise" do
|
8
|
-
lambda { Caricature::Isolation.for(Soldier) }.should_not raise_error
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "after creation of the isolation for a ruby object" do
|
14
|
-
|
15
|
-
before do
|
16
|
-
@isolator = Caricature::Isolation.for(Soldier)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should create a proxy" do
|
20
|
-
@isolator.should_not be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when asked to stub a method" do
|
24
|
-
|
25
|
-
it "should create an expectation with a block" do
|
26
|
-
nm = "What's in a name"
|
27
|
-
expectation = @isolator.when_receiving(:name) do |cl|
|
28
|
-
cl.return(nm)
|
29
|
-
end
|
30
|
-
expectation.method_name.should == :name
|
31
|
-
expectation.should be_has_return_value
|
32
|
-
expectation.return_value.should == nm
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should create an expectation without a block" do
|
36
|
-
nm = "What's in a name"
|
37
|
-
expectation = @isolator.when_receiving(:name).return(nm)
|
38
|
-
expectation.method_name.should == :name
|
39
|
-
expectation.should be_has_return_value
|
40
|
-
expectation.return_value.should == nm
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when creating an isolation for CLR objects" do
|
47
|
-
|
48
|
-
it "should not raise" do
|
49
|
-
lambda { Caricature::Isolation.for(ClrModels::Ninja) }.should_not raise_error
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "after creation of the isolation for a CLR object" do
|
55
|
-
|
56
|
-
before do
|
57
|
-
@isolator = Caricature::Isolation.for(ClrModels::Ninja)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should create a proxy" do
|
61
|
-
@isolator.should_not be_nil
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "when asked to stub a method" do
|
65
|
-
|
66
|
-
it "should create an expectation with a block" do
|
67
|
-
nm = "What's in a name"
|
68
|
-
expectation = @isolator.when_receiving(:name) do |cl|
|
69
|
-
cl.return(nm)
|
70
|
-
end
|
71
|
-
expectation.method_name.should == :name
|
72
|
-
expectation.should be_has_return_value
|
73
|
-
expectation.return_value.should == nm
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should create an expectation without a block" do
|
77
|
-
nm = "What's in a name"
|
78
|
-
expectation = @isolator.when_receiving(:name).return(nm)
|
79
|
-
expectation.method_name.should == :name
|
80
|
-
expectation.should be_has_return_value
|
81
|
-
expectation.return_value.should == nm
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "Caricature::Isolation" do
|
4
|
+
|
5
|
+
describe "when creating an isolation for ruby objects" do
|
6
|
+
|
7
|
+
it "should not raise" do
|
8
|
+
lambda { Caricature::Isolation.for(Soldier) }.should_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "after creation of the isolation for a ruby object" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@isolator = Caricature::Isolation.for(Soldier)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create a proxy" do
|
20
|
+
@isolator.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when asked to stub a method" do
|
24
|
+
|
25
|
+
it "should create an expectation with a block" do
|
26
|
+
nm = "What's in a name"
|
27
|
+
expectation = @isolator.when_receiving(:name) do |cl|
|
28
|
+
cl.return(nm)
|
29
|
+
end
|
30
|
+
expectation.method_name.should == :name
|
31
|
+
expectation.should be_has_return_value
|
32
|
+
expectation.return_value.should == nm
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create an expectation without a block" do
|
36
|
+
nm = "What's in a name"
|
37
|
+
expectation = @isolator.when_receiving(:name).return(nm)
|
38
|
+
expectation.method_name.should == :name
|
39
|
+
expectation.should be_has_return_value
|
40
|
+
expectation.return_value.should == nm
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when creating an isolation for CLR objects" do
|
47
|
+
|
48
|
+
it "should not raise" do
|
49
|
+
lambda { Caricature::Isolation.for(ClrModels::Ninja) }.should_not raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "after creation of the isolation for a CLR object" do
|
55
|
+
|
56
|
+
before do
|
57
|
+
@isolator = Caricature::Isolation.for(ClrModels::Ninja)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should create a proxy" do
|
61
|
+
@isolator.should_not be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "when asked to stub a method" do
|
65
|
+
|
66
|
+
it "should create an expectation with a block" do
|
67
|
+
nm = "What's in a name"
|
68
|
+
expectation = @isolator.when_receiving(:name) do |cl|
|
69
|
+
cl.return(nm)
|
70
|
+
end
|
71
|
+
expectation.method_name.should == :name
|
72
|
+
expectation.should be_has_return_value
|
73
|
+
expectation.return_value.should == nm
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should create an expectation without a block" do
|
77
|
+
nm = "What's in a name"
|
78
|
+
expectation = @isolator.when_receiving(:name).return(nm)
|
79
|
+
expectation.method_name.should == :name
|
80
|
+
expectation.should be_has_return_value
|
81
|
+
expectation.return_value.should == nm
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
87
|
end
|
@@ -1,220 +1,220 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
class TestIsolation
|
4
|
-
attr_accessor :instance, :expectations
|
5
|
-
def initialize(instance, expectations)
|
6
|
-
@instance, @expectations = instance, expectations
|
7
|
-
end
|
8
|
-
def send_message(method_name, return_type, *args, &b)
|
9
|
-
internal_send method_name, :internal, return_type, *args, &b
|
10
|
-
end
|
11
|
-
def send_class_message(method_name, return_type, *args, &b)
|
12
|
-
internal_send method_name, :class, return_type, *args, &b
|
13
|
-
end
|
14
|
-
def internal_send(method_name, mode, return_type, *args, &b)
|
15
|
-
exp = expectations.find(method_name, mode, *args)
|
16
|
-
if exp
|
17
|
-
res = instance.__send__(method_name, *args, &b) if exp.super_before?
|
18
|
-
res = exp.execute(*args)
|
19
|
-
res = instance.__send__(method_name, *args, &b) if !exp.super_before? and exp.call_super?
|
20
|
-
res
|
21
|
-
else
|
22
|
-
rt = nil
|
23
|
-
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
24
|
-
rt = System::Activator.create_instance(return_type) if is_value_type
|
25
|
-
rt
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "Caricature::RubyIsolator" do
|
31
|
-
|
32
|
-
before do
|
33
|
-
@subj = Soldier.new
|
34
|
-
res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(@subj)
|
35
|
-
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
36
|
-
@proxy = res.isolation
|
37
|
-
@proxy.class.instance_variable_set("@___context___", iso)
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
describe "when invoking a method" do
|
42
|
-
|
43
|
-
before do
|
44
|
-
@proxy.name
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return nil" do
|
48
|
-
@proxy.name.should be_nil
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "when isolating a class with class members" do
|
54
|
-
|
55
|
-
before do
|
56
|
-
res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(DaggerWithClassMembers)
|
57
|
-
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
58
|
-
@proxy = res.isolation
|
59
|
-
@proxy.class.instance_variable_set("@___context___", iso)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return nil for the class method" do
|
63
|
-
|
64
|
-
@proxy.class.class_name.should be_nil
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "Caricature::RecordingClrProxy" do
|
72
|
-
|
73
|
-
describe "for an instance of a CLR class" do
|
74
|
-
|
75
|
-
before do
|
76
|
-
@ninja = ClrModels::Ninja.new
|
77
|
-
@ninja.name = "Nakiro"
|
78
|
-
context = Caricature::IsolatorContext.new(@ninja)
|
79
|
-
res = Caricature::ClrIsolator.for context
|
80
|
-
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
81
|
-
@proxy = res.isolation
|
82
|
-
@proxy.class.instance_variable_set("@___context___", iso)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should create a proxy" do
|
86
|
-
|
87
|
-
@proxy.___super___.name.should == @ninja.name
|
88
|
-
@proxy.___super___.id.should == 1
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "when invoking a method" do
|
92
|
-
|
93
|
-
before do
|
94
|
-
@proxy.name
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should return nil" do
|
98
|
-
@proxy.name.should be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "when isolating a class with class members" do
|
104
|
-
|
105
|
-
before do
|
106
|
-
res = Caricature::ClrIsolator.for Caricature::IsolatorContext.new(ClrModels::SwordWithStatics)
|
107
|
-
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
108
|
-
@proxy = res.isolation
|
109
|
-
@proxy.class.instance_variable_set("@___context___", iso)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should return nil for the class method" do
|
113
|
-
|
114
|
-
@proxy.class.class_naming.should be_nil
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "for a CLR class" do
|
123
|
-
|
124
|
-
before do
|
125
|
-
@recorder = Caricature::MethodCallRecorder.new
|
126
|
-
context = Caricature::IsolatorContext.new(ClrModels::Ninja, @recorder)
|
127
|
-
res = Caricature::ClrIsolator.for context
|
128
|
-
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
129
|
-
@proxy = res.isolation
|
130
|
-
@proxy.class.instance_variable_set("@___context___", iso)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should create a proxy" do
|
134
|
-
|
135
|
-
@proxy.class.superclass.should == ClrModels::Ninja
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "for a CLR interface" do
|
143
|
-
|
144
|
-
before do
|
145
|
-
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IWarrior)
|
146
|
-
@proxy = res.isolation
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should create a proxy" do
|
150
|
-
@proxy.class.to_s.should match(/^IWarrior/)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should create a method on the proxy" do
|
154
|
-
@proxy.should respond_to(:is_killed_by)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should create a getter for a property on the proxy" do
|
158
|
-
@proxy.should respond_to(:id)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should create a setter for a writable property on the proxy" do
|
162
|
-
@proxy.should respond_to(:name=)
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "for a CLR Interface with an event" do
|
168
|
-
|
169
|
-
before do
|
170
|
-
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposing)
|
171
|
-
@proxy = res.isolation
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should create an add method for the event" do
|
175
|
-
@proxy.should respond_to(:add_is_exposed_changed)
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should create a remove method for the event" do
|
179
|
-
@proxy.should respond_to(:remove_is_exposed_changed)
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "for CLR interface recursion" do
|
185
|
-
|
186
|
-
before do
|
187
|
-
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposingWarrior)
|
188
|
-
@proxy = res.isolation
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should create a method defined on the CLR interface" do
|
192
|
-
@proxy.should respond_to(:own_method)
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should create a method defined on one of the composing interfaces" do
|
196
|
-
@proxy.should respond_to(:some_method)
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should create a method defined on one of the topmost composing interfaces" do
|
200
|
-
@proxy.should respond_to(:is_killed_by)
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should create an add method for an event defined on a composing interface" do
|
204
|
-
@proxy.should respond_to(:add_is_exposed_changed)
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should create a remove method for an event defined on a composing interface" do
|
208
|
-
@proxy.should respond_to(:remove_is_exposed_changed)
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should create a getter for a property on the proxy" do
|
212
|
-
@proxy.should respond_to(:id)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should create a setter for a writable property on the proxy" do
|
216
|
-
@proxy.should respond_to(:name=)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
class TestIsolation
|
4
|
+
attr_accessor :instance, :expectations
|
5
|
+
def initialize(instance, expectations)
|
6
|
+
@instance, @expectations = instance, expectations
|
7
|
+
end
|
8
|
+
def send_message(method_name, return_type, *args, &b)
|
9
|
+
internal_send method_name, :internal, return_type, *args, &b
|
10
|
+
end
|
11
|
+
def send_class_message(method_name, return_type, *args, &b)
|
12
|
+
internal_send method_name, :class, return_type, *args, &b
|
13
|
+
end
|
14
|
+
def internal_send(method_name, mode, return_type, *args, &b)
|
15
|
+
exp = expectations.find(method_name, mode, *args)
|
16
|
+
if exp
|
17
|
+
res = instance.__send__(method_name, *args, &b) if exp.super_before?
|
18
|
+
res = exp.execute(*args)
|
19
|
+
res = instance.__send__(method_name, *args, &b) if !exp.super_before? and exp.call_super?
|
20
|
+
res
|
21
|
+
else
|
22
|
+
rt = nil
|
23
|
+
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
24
|
+
rt = System::Activator.create_instance(return_type) if is_value_type
|
25
|
+
rt
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "Caricature::RubyIsolator" do
|
31
|
+
|
32
|
+
before do
|
33
|
+
@subj = Soldier.new
|
34
|
+
res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(@subj)
|
35
|
+
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
36
|
+
@proxy = res.isolation
|
37
|
+
@proxy.class.instance_variable_set("@___context___", iso)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe "when invoking a method" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
@proxy.name
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil" do
|
48
|
+
@proxy.name.should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "when isolating a class with class members" do
|
54
|
+
|
55
|
+
before do
|
56
|
+
res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(DaggerWithClassMembers)
|
57
|
+
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
58
|
+
@proxy = res.isolation
|
59
|
+
@proxy.class.instance_variable_set("@___context___", iso)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return nil for the class method" do
|
63
|
+
|
64
|
+
@proxy.class.class_name.should be_nil
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "Caricature::RecordingClrProxy" do
|
72
|
+
|
73
|
+
describe "for an instance of a CLR class" do
|
74
|
+
|
75
|
+
before do
|
76
|
+
@ninja = ClrModels::Ninja.new
|
77
|
+
@ninja.name = "Nakiro"
|
78
|
+
context = Caricature::IsolatorContext.new(@ninja)
|
79
|
+
res = Caricature::ClrIsolator.for context
|
80
|
+
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
81
|
+
@proxy = res.isolation
|
82
|
+
@proxy.class.instance_variable_set("@___context___", iso)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should create a proxy" do
|
86
|
+
|
87
|
+
@proxy.___super___.name.should == @ninja.name
|
88
|
+
@proxy.___super___.id.should == 1
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "when invoking a method" do
|
92
|
+
|
93
|
+
before do
|
94
|
+
@proxy.name
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return nil" do
|
98
|
+
@proxy.name.should be_nil
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "when isolating a class with class members" do
|
104
|
+
|
105
|
+
before do
|
106
|
+
res = Caricature::ClrIsolator.for Caricature::IsolatorContext.new(ClrModels::SwordWithStatics)
|
107
|
+
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
108
|
+
@proxy = res.isolation
|
109
|
+
@proxy.class.instance_variable_set("@___context___", iso)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return nil for the class method" do
|
113
|
+
|
114
|
+
@proxy.class.class_naming.should be_nil
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "for a CLR class" do
|
123
|
+
|
124
|
+
before do
|
125
|
+
@recorder = Caricature::MethodCallRecorder.new
|
126
|
+
context = Caricature::IsolatorContext.new(ClrModels::Ninja, @recorder)
|
127
|
+
res = Caricature::ClrIsolator.for context
|
128
|
+
iso = TestIsolation.new res.subject, Caricature::Expectations.new
|
129
|
+
@proxy = res.isolation
|
130
|
+
@proxy.class.instance_variable_set("@___context___", iso)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should create a proxy" do
|
134
|
+
|
135
|
+
@proxy.class.superclass.should == ClrModels::Ninja
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "for a CLR interface" do
|
143
|
+
|
144
|
+
before do
|
145
|
+
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IWarrior)
|
146
|
+
@proxy = res.isolation
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should create a proxy" do
|
150
|
+
@proxy.class.to_s.should match(/^IWarrior/)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should create a method on the proxy" do
|
154
|
+
@proxy.should respond_to(:is_killed_by)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should create a getter for a property on the proxy" do
|
158
|
+
@proxy.should respond_to(:id)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should create a setter for a writable property on the proxy" do
|
162
|
+
@proxy.should respond_to(:name=)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "for a CLR Interface with an event" do
|
168
|
+
|
169
|
+
before do
|
170
|
+
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposing)
|
171
|
+
@proxy = res.isolation
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should create an add method for the event" do
|
175
|
+
@proxy.should respond_to(:add_is_exposed_changed)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should create a remove method for the event" do
|
179
|
+
@proxy.should respond_to(:remove_is_exposed_changed)
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "for CLR interface recursion" do
|
185
|
+
|
186
|
+
before do
|
187
|
+
res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposingWarrior)
|
188
|
+
@proxy = res.isolation
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should create a method defined on the CLR interface" do
|
192
|
+
@proxy.should respond_to(:own_method)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should create a method defined on one of the composing interfaces" do
|
196
|
+
@proxy.should respond_to(:some_method)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should create a method defined on one of the topmost composing interfaces" do
|
200
|
+
@proxy.should respond_to(:is_killed_by)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should create an add method for an event defined on a composing interface" do
|
204
|
+
@proxy.should respond_to(:add_is_exposed_changed)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should create a remove method for an event defined on a composing interface" do
|
208
|
+
@proxy.should respond_to(:remove_is_exposed_changed)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should create a getter for a property on the proxy" do
|
212
|
+
@proxy.should respond_to(:id)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should create a setter for a writable property on the proxy" do
|
216
|
+
@proxy.should respond_to(:name=)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
220
|
end
|