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
@@ -1,30 +1,30 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "Event handling" do
4
-
5
-
6
-
7
- describe "for precompiled CLR classes" do
8
-
9
- before do
10
- @warrior = ClrModels::ExposingWarrior.new
11
- end
12
-
13
- it "should subscribe to an event" do
14
- ClrModels::ExposedChangedSubscriber.new(@warrior)
15
- @warrior.has_event_subscriptions.should.be.true?
16
- end
17
-
18
- it "should not raise an error when subcribing to an event" do
19
- lambda { ClrModels::ExposedChangedSubscriber.new(@warrior) }.should.not.raise
20
- end
21
-
22
- it "should handle an event when raised" do
23
- subscriber = ClrModels::ExposedChangedSubscriber.new(@warrior)
24
- @warrior.change_is_exposed
25
- subscriber.counter.should.equal 1
26
- end
27
-
28
- end
29
-
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "Event handling" do
4
+
5
+
6
+
7
+ describe "for precompiled CLR classes" do
8
+
9
+ before do
10
+ @warrior = ClrModels::ExposingWarrior.new
11
+ end
12
+
13
+ it "should subscribe to an event" do
14
+ ClrModels::ExposedChangedSubscriber.new(@warrior)
15
+ @warrior.has_event_subscriptions.should.be.true?
16
+ end
17
+
18
+ it "should not raise an error when subcribing to an event" do
19
+ lambda { ClrModels::ExposedChangedSubscriber.new(@warrior) }.should.not.raise
20
+ end
21
+
22
+ it "should handle an event when raised" do
23
+ subscriber = ClrModels::ExposedChangedSubscriber.new(@warrior)
24
+ @warrior.change_is_exposed
25
+ subscriber.counter.should.equal 1
26
+ end
27
+
28
+ end
29
+
30
30
  end
@@ -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
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.equal :name
31
- expectation.has_return_value?.should.be.true?
32
- expectation.return_value.should.equal 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.equal :name
39
- expectation.has_return_value?.should.be.true?
40
- expectation.return_value.should.equal 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
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.equal :name
72
- expectation.has_return_value?.should.be.true?
73
- expectation.return_value.should.equal 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.equal :name
80
- expectation.has_return_value?.should.be.true?
81
- expectation.return_value.should.equal 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
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.equal :name
31
+ expectation.has_return_value?.should.be.true?
32
+ expectation.return_value.should.equal 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.equal :name
39
+ expectation.has_return_value?.should.be.true?
40
+ expectation.return_value.should.equal 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
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.equal :name
72
+ expectation.has_return_value?.should.be.true?
73
+ expectation.return_value.should.equal 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.equal :name
80
+ expectation.has_return_value?.should.be.true?
81
+ expectation.return_value.should.equal 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::ClrIsolator" 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.equal @ninja.name
88
- @proxy.___super___.id.should.equal 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.equal 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_OnIsExposedChanged)
176
- end
177
-
178
- it "should create a remove method for the event" do
179
- @proxy.should.respond_to?(:remove_OnIsExposedChanged)
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_OnIsExposedChanged)
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_OnIsExposedChanged)
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::ClrIsolator" 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.equal @ninja.name
88
+ @proxy.___super___.id.should.equal 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.equal 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_OnIsExposedChanged)
176
+ end
177
+
178
+ it "should create a remove method for the event" do
179
+ @proxy.should.respond_to?(:remove_OnIsExposedChanged)
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_OnIsExposedChanged)
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_OnIsExposedChanged)
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