caricature 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +98 -0
- data/Rakefile +250 -47
- data/caricature.gemspec +79 -190
- data/lib/caricature/clr/descriptor.rb +14 -4
- data/lib/caricature/clr/isolation.rb +9 -0
- data/lib/caricature/clr/isolator.rb +4 -0
- data/lib/caricature/clr/messenger.rb +12 -17
- data/lib/caricature/clr.rb +1 -1
- data/lib/caricature/descriptor.rb +1 -1
- data/lib/caricature/expectation.rb +21 -11
- data/lib/caricature/isolation.rb +9 -3
- data/lib/caricature/isolator.rb +25 -9
- data/lib/caricature/messenger.rb +1 -1
- data/lib/caricature/verification.rb +2 -1
- data/lib/caricature/version.rb +6 -0
- data/lib/caricature.rb +8 -5
- data/spec/bacon_helper.rb +50 -30
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/integration/callback_spec.rb +157 -0
- data/spec/integration/ruby_to_ruby_spec.rb +12 -1
- data/spec/models/ClrModels.cs +8 -8
- data/spec/unit/expectation_spec.rb +35 -0
- metadata +35 -125
- data/.gitignore +0 -4
- data/README.markdown +0 -80
- data/VERSION +0 -1
- data/doc/Array.html +0 -251
- data/doc/Caricature/ArgumentRecording.html +0 -366
- data/doc/Caricature/ClrClassDescriptor.html +0 -303
- data/doc/Caricature/ClrClassMessenger.html +0 -263
- data/doc/Caricature/ClrInterfaceDescriptor.html +0 -295
- data/doc/Caricature/ClrInterfaceIsolator.html +0 -365
- data/doc/Caricature/ClrInterfaceMessenger.html +0 -260
- data/doc/Caricature/ClrIsolator.html +0 -425
- data/doc/Caricature/Expectation.html +0 -549
- data/doc/Caricature/ExpectationBuilder.html +0 -308
- data/doc/Caricature/ExpectationSyntax.html +0 -466
- data/doc/Caricature/Expectations.html +0 -347
- data/doc/Caricature/Interception/ClassMethods.html +0 -364
- data/doc/Caricature/Interception.html +0 -534
- data/doc/Caricature/Isolation.html +0 -763
- data/doc/Caricature/Isolator.html +0 -519
- data/doc/Caricature/MemberDescriptor.html +0 -335
- data/doc/Caricature/Messenger.html +0 -413
- data/doc/Caricature/MethodCallRecorder.html +0 -404
- data/doc/Caricature/MethodCallRecording.html +0 -493
- data/doc/Caricature/RubyIsolator.html +0 -416
- data/doc/Caricature/RubyMessenger.html +0 -261
- data/doc/Caricature/RubyObjectDescriptor.html +0 -289
- data/doc/Caricature/TypeDescriptor.html +0 -378
- data/doc/Caricature/Verification.html +0 -443
- data/doc/Caricature.html +0 -358
- data/doc/Class.html +0 -287
- data/doc/Hash.html +0 -255
- data/doc/Module.html +0 -287
- data/doc/Object.html +0 -409
- data/doc/README_markdown.html +0 -241
- data/doc/String.html +0 -369
- data/doc/System/String.html +0 -289
- data/doc/System/Type.html +0 -289
- data/doc/System.html +0 -207
- data/doc/created.rid +0 -1
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -342
- data/doc/js/darkfish.js +0 -116
- data/doc/js/jquery.js +0 -32
- data/doc/js/quicksearch.js +0 -114
- data/doc/js/thickbox-compressed.js +0 -10
- data/doc/lib/caricature/clr/aspnet_mvc_rb.html +0 -52
- data/doc/lib/caricature/clr/descriptor_rb.html +0 -52
- data/doc/lib/caricature/clr/isolation_rb.html +0 -52
- data/doc/lib/caricature/clr/isolator_rb.html +0 -52
- data/doc/lib/caricature/clr/messenger_rb.html +0 -52
- data/doc/lib/caricature/clr_rb.html +0 -52
- data/doc/lib/caricature/descriptor_rb.html +0 -52
- data/doc/lib/caricature/expectation_rb.html +0 -52
- data/doc/lib/caricature/isolation_rb.html +0 -52
- data/doc/lib/caricature/isolator_rb.html +0 -52
- data/doc/lib/caricature/messaging_rb.html +0 -52
- data/doc/lib/caricature/messenger_rb.html +0 -52
- data/doc/lib/caricature/method_call_recorder_rb.html +0 -52
- data/doc/lib/caricature/verification_rb.html +0 -52
- data/doc/lib/caricature_rb.html +0 -52
- data/doc/lib/core_ext/array_rb.html +0 -52
- data/doc/lib/core_ext/class_rb.html +0 -52
- data/doc/lib/core_ext/core_ext_rb.html +0 -52
- data/doc/lib/core_ext/hash_rb.html +0 -52
- data/doc/lib/core_ext/module_rb.html +0 -52
- data/doc/lib/core_ext/object_rb.html +0 -52
- data/doc/lib/core_ext/string_rb.html +0 -52
- data/doc/lib/core_ext/system/string_rb.html +0 -52
- data/doc/lib/core_ext/system/type_rb.html +0 -52
- data/doc/rdoc.css +0 -696
- data/irb_init.rb +0 -9
- data/lib/bin/Workarounds.dll +0 -0
- data/lib/bin/Workarounds.pdb +0 -0
- data/pkg/.gitignore +0 -0
- data/pkg/caricature-0.1.0.gem +0 -0
- data/pkg/caricature-0.5.0.gem +0 -0
- data/pkg/caricature-0.6.0.gem +0 -0
- data/spec/bin/.gitignore +0 -0
- data/workarounds/ReflectionHelper.cs +0 -30
data/caricature.gemspec
CHANGED
@@ -1,190 +1,79 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
s.
|
6
|
-
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
"doc/js/quicksearch.js",
|
81
|
-
"doc/js/thickbox-compressed.js",
|
82
|
-
"doc/lib/caricature/clr/aspnet_mvc_rb.html",
|
83
|
-
"doc/lib/caricature/clr/descriptor_rb.html",
|
84
|
-
"doc/lib/caricature/clr/isolation_rb.html",
|
85
|
-
"doc/lib/caricature/clr/isolator_rb.html",
|
86
|
-
"doc/lib/caricature/clr/messenger_rb.html",
|
87
|
-
"doc/lib/caricature/clr_rb.html",
|
88
|
-
"doc/lib/caricature/descriptor_rb.html",
|
89
|
-
"doc/lib/caricature/expectation_rb.html",
|
90
|
-
"doc/lib/caricature/isolation_rb.html",
|
91
|
-
"doc/lib/caricature/isolator_rb.html",
|
92
|
-
"doc/lib/caricature/messaging_rb.html",
|
93
|
-
"doc/lib/caricature/messenger_rb.html",
|
94
|
-
"doc/lib/caricature/method_call_recorder_rb.html",
|
95
|
-
"doc/lib/caricature/verification_rb.html",
|
96
|
-
"doc/lib/caricature_rb.html",
|
97
|
-
"doc/lib/core_ext/array_rb.html",
|
98
|
-
"doc/lib/core_ext/class_rb.html",
|
99
|
-
"doc/lib/core_ext/core_ext_rb.html",
|
100
|
-
"doc/lib/core_ext/hash_rb.html",
|
101
|
-
"doc/lib/core_ext/module_rb.html",
|
102
|
-
"doc/lib/core_ext/object_rb.html",
|
103
|
-
"doc/lib/core_ext/string_rb.html",
|
104
|
-
"doc/lib/core_ext/system/string_rb.html",
|
105
|
-
"doc/lib/core_ext/system/type_rb.html",
|
106
|
-
"doc/rdoc.css",
|
107
|
-
"irb_init.rb",
|
108
|
-
"lib/bin/Workarounds.dll",
|
109
|
-
"lib/bin/Workarounds.pdb",
|
110
|
-
"lib/caricature.rb",
|
111
|
-
"lib/caricature/clr.rb",
|
112
|
-
"lib/caricature/clr/aspnet_mvc.rb",
|
113
|
-
"lib/caricature/clr/descriptor.rb",
|
114
|
-
"lib/caricature/clr/isolation.rb",
|
115
|
-
"lib/caricature/clr/isolator.rb",
|
116
|
-
"lib/caricature/clr/messenger.rb",
|
117
|
-
"lib/caricature/descriptor.rb",
|
118
|
-
"lib/caricature/expectation.rb",
|
119
|
-
"lib/caricature/isolation.rb",
|
120
|
-
"lib/caricature/isolator.rb",
|
121
|
-
"lib/caricature/messenger.rb",
|
122
|
-
"lib/caricature/method_call_recorder.rb",
|
123
|
-
"lib/caricature/verification.rb",
|
124
|
-
"lib/core_ext/array.rb",
|
125
|
-
"lib/core_ext/class.rb",
|
126
|
-
"lib/core_ext/core_ext.rb",
|
127
|
-
"lib/core_ext/hash.rb",
|
128
|
-
"lib/core_ext/module.rb",
|
129
|
-
"lib/core_ext/object.rb",
|
130
|
-
"lib/core_ext/string.rb",
|
131
|
-
"lib/core_ext/system/string.rb",
|
132
|
-
"lib/core_ext/system/type.rb",
|
133
|
-
"pkg/.gitignore",
|
134
|
-
"pkg/caricature-0.1.0.gem",
|
135
|
-
"pkg/caricature-0.5.0.gem",
|
136
|
-
"pkg/caricature-0.6.0.gem",
|
137
|
-
"spec/bacon_helper.rb",
|
138
|
-
"spec/bin/.gitignore",
|
139
|
-
"spec/integration/clr_to_clr_spec.rb",
|
140
|
-
"spec/integration/clr_to_ruby_spec.rb",
|
141
|
-
"spec/integration/indexer_spec.rb",
|
142
|
-
"spec/integration/ruby_to_ruby_spec.rb",
|
143
|
-
"spec/models/ClrModels.cs",
|
144
|
-
"spec/unit/core_ext_spec.rb",
|
145
|
-
"spec/unit/descriptor_spec.rb",
|
146
|
-
"spec/unit/expectation_spec.rb",
|
147
|
-
"spec/unit/interop_spec.rb",
|
148
|
-
"spec/unit/isolation_spec.rb",
|
149
|
-
"spec/unit/isolator_spec.rb",
|
150
|
-
"spec/unit/messaging_spec.rb",
|
151
|
-
"spec/unit/method_call_spec.rb",
|
152
|
-
"spec/unit/sword_spec.rb",
|
153
|
-
"spec/unit/verification_spec.rb",
|
154
|
-
"workarounds/ReflectionHelper.cs"
|
155
|
-
]
|
156
|
-
s.has_rdoc = true
|
157
|
-
s.homepage = %q{http://github.com/casualjim/caricature}
|
158
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
159
|
-
s.require_paths = ["lib"]
|
160
|
-
s.rubyforge_project = %q{caricature}
|
161
|
-
s.rubygems_version = %q{1.3.2}
|
162
|
-
s.summary = %q{Caricature - Bringing simple mocking to the DLR}
|
163
|
-
s.test_files = [
|
164
|
-
"spec/bacon_helper.rb",
|
165
|
-
"spec/integration/clr_to_clr_spec.rb",
|
166
|
-
"spec/integration/clr_to_ruby_spec.rb",
|
167
|
-
"spec/integration/indexer_spec.rb",
|
168
|
-
"spec/integration/ruby_to_ruby_spec.rb",
|
169
|
-
"spec/unit/core_ext_spec.rb",
|
170
|
-
"spec/unit/descriptor_spec.rb",
|
171
|
-
"spec/unit/expectation_spec.rb",
|
172
|
-
"spec/unit/interop_spec.rb",
|
173
|
-
"spec/unit/isolation_spec.rb",
|
174
|
-
"spec/unit/isolator_spec.rb",
|
175
|
-
"spec/unit/messaging_spec.rb",
|
176
|
-
"spec/unit/method_call_spec.rb",
|
177
|
-
"spec/unit/sword_spec.rb",
|
178
|
-
"spec/unit/verification_spec.rb"
|
179
|
-
]
|
180
|
-
|
181
|
-
if s.respond_to? :specification_version then
|
182
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
183
|
-
s.specification_version = 3
|
184
|
-
|
185
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
186
|
-
else
|
187
|
-
end
|
188
|
-
else
|
189
|
-
end
|
190
|
-
end
|
1
|
+
# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
|
2
|
+
# RUN : 'rake gem:update_gemspec'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Ivan Porto Carrero"]
|
6
|
+
s.bindir = "bin"
|
7
|
+
s.add_dependency "uuidtools", ">= 2.0.0, runtime"
|
8
|
+
s.description = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
9
|
+
s.email = "ivan@flanders.co.nz"
|
10
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
11
|
+
s.files = ["README.rdoc",
|
12
|
+
"Rakefile",
|
13
|
+
"caricature.gemspec",
|
14
|
+
"lib/caricature",
|
15
|
+
"lib/caricature.rb",
|
16
|
+
"lib/caricature/clr",
|
17
|
+
"lib/caricature/clr.rb",
|
18
|
+
"lib/caricature/clr/aspnet_mvc.rb",
|
19
|
+
"lib/caricature/clr/descriptor.rb",
|
20
|
+
"lib/caricature/clr/isolation.rb",
|
21
|
+
"lib/caricature/clr/isolator.rb",
|
22
|
+
"lib/caricature/clr/messenger.rb",
|
23
|
+
"lib/caricature/descriptor.rb",
|
24
|
+
"lib/caricature/expectation.rb",
|
25
|
+
"lib/caricature/isolation.rb",
|
26
|
+
"lib/caricature/isolator.rb",
|
27
|
+
"lib/caricature/messenger.rb",
|
28
|
+
"lib/caricature/method_call_recorder.rb",
|
29
|
+
"lib/caricature/verification.rb",
|
30
|
+
"lib/caricature/version.rb",
|
31
|
+
"lib/core_ext",
|
32
|
+
"lib/core_ext/array.rb",
|
33
|
+
"lib/core_ext/class.rb",
|
34
|
+
"lib/core_ext/core_ext.rb",
|
35
|
+
"lib/core_ext/hash.rb",
|
36
|
+
"lib/core_ext/module.rb",
|
37
|
+
"lib/core_ext/object.rb",
|
38
|
+
"lib/core_ext/string.rb",
|
39
|
+
"lib/core_ext/system",
|
40
|
+
"lib/core_ext/system/string.rb",
|
41
|
+
"lib/core_ext/system/type.rb",
|
42
|
+
"spec/bacon_helper.rb",
|
43
|
+
"spec/bin",
|
44
|
+
"spec/bin/ClrModels.dll",
|
45
|
+
"spec/bin/ClrModels.dll.mdb",
|
46
|
+
"spec/integration",
|
47
|
+
"spec/integration/callback_spec.rb",
|
48
|
+
"spec/integration/clr_to_clr_spec.rb",
|
49
|
+
"spec/integration/clr_to_ruby_spec.rb",
|
50
|
+
"spec/integration/indexer_spec.rb",
|
51
|
+
"spec/integration/ruby_to_ruby_spec.rb",
|
52
|
+
"spec/models",
|
53
|
+
"spec/models/ClrModels.cs",
|
54
|
+
"spec/unit",
|
55
|
+
"spec/unit/core_ext_spec.rb",
|
56
|
+
"spec/unit/descriptor_spec.rb",
|
57
|
+
"spec/unit/expectation_spec.rb",
|
58
|
+
"spec/unit/interop_spec.rb",
|
59
|
+
"spec/unit/isolation_spec.rb",
|
60
|
+
"spec/unit/isolator_spec.rb",
|
61
|
+
"spec/unit/messaging_spec.rb",
|
62
|
+
"spec/unit/method_call_spec.rb",
|
63
|
+
"spec/unit/sword_spec.rb",
|
64
|
+
"spec/unit/verification_spec.rb"]
|
65
|
+
s.has_rdoc = true
|
66
|
+
s.homepage = "http://casualjim.github.com/caricature"
|
67
|
+
s.loaded = false
|
68
|
+
s.name = "caricature"
|
69
|
+
s.platform = "ruby"
|
70
|
+
s.rdoc_options = ["--quiet", "--title", "Caricature brings simple mocking to Ruby, DLR and CLR.", "--main", "lib/caricature/isolation.rb", "--line-numbers", "--inline-source", "--format", "darkfish"]
|
71
|
+
s.require_paths = ["lib"]
|
72
|
+
s.required_ruby_version = ">= 1.8.4"
|
73
|
+
s.required_rubygems_version = ">= 0"
|
74
|
+
s.rubyforge_project = "caricature"
|
75
|
+
s.rubygems_version = "1.3.5"
|
76
|
+
s.specification_version = 3
|
77
|
+
s.summary = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
78
|
+
s.version = "0.7.0"
|
79
|
+
end
|
@@ -26,6 +26,16 @@ module Caricature
|
|
26
26
|
def property_name_from(property_info)
|
27
27
|
return property_info.name.underscore if property_info.get_index_parameters.empty?
|
28
28
|
"__getitem__"
|
29
|
+
end
|
30
|
+
|
31
|
+
# the binding flags for instance members of a CLR type
|
32
|
+
def instance_flags
|
33
|
+
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.instance
|
34
|
+
end
|
35
|
+
|
36
|
+
# the binding flags for class members of a CLR type
|
37
|
+
def class_flags
|
38
|
+
System::Reflection::BindingFlags.public | System::Reflection::BindingFlags.static
|
29
39
|
end
|
30
40
|
|
31
41
|
end
|
@@ -62,8 +72,8 @@ module Caricature
|
|
62
72
|
def initialize_instance_members_for(klass)
|
63
73
|
clr_type = klass.to_clr_type
|
64
74
|
|
65
|
-
methods =
|
66
|
-
properties =
|
75
|
+
methods = clr_type.get_methods(instance_flags)
|
76
|
+
properties = clr_type.get_properties(instance_flags)
|
67
77
|
|
68
78
|
@instance_members = collect_members_from methods, properties
|
69
79
|
end
|
@@ -72,8 +82,8 @@ module Caricature
|
|
72
82
|
def initialize_class_members_for(klass)
|
73
83
|
clr_type = klass.to_clr_type
|
74
84
|
|
75
|
-
methods =
|
76
|
-
properties =
|
85
|
+
methods = clr_type.get_methods(class_flags)
|
86
|
+
properties = clr_type.get_properties(class_flags)
|
77
87
|
|
78
88
|
@class_members = collect_members_from methods, properties, false
|
79
89
|
end
|
@@ -1,6 +1,15 @@
|
|
1
1
|
module Caricature
|
2
2
|
|
3
3
|
class Isolation
|
4
|
+
|
5
|
+
def internal_create_override(method_name, mode=:instance, &block)
|
6
|
+
builder = ExpectationBuilder.new method_name
|
7
|
+
block.call builder unless block.nil?
|
8
|
+
exp = builder.build
|
9
|
+
|
10
|
+
expectations.add_expectation exp, mode
|
11
|
+
exp
|
12
|
+
end
|
4
13
|
|
5
14
|
class << self
|
6
15
|
|
@@ -6,19 +6,17 @@ module Caricature
|
|
6
6
|
protected
|
7
7
|
|
8
8
|
# deliver the message to the receiving isolation
|
9
|
-
def internal_deliver(mode, method_name, return_type, *args, &b)
|
10
|
-
exp = expectations.find(method_name, mode, *args)
|
9
|
+
def internal_deliver(mode, method_name, return_type, *args, &b)
|
10
|
+
exp = expectations.find(method_name, mode, *args)
|
11
|
+
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
12
|
+
res = nil
|
11
13
|
if exp
|
12
14
|
res = instance.__send__(method_name, *args, &b) if exp.super_before?
|
13
15
|
res = exp.execute *args
|
14
16
|
res = instance.__send__(method_name, *args, &b) if !exp.super_before? and exp.call_super?
|
15
|
-
res
|
16
|
-
else
|
17
|
-
rt = nil
|
18
|
-
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
19
|
-
rt = System::Activator.create_instance(return_type) if is_value_type
|
20
|
-
rt
|
21
17
|
end
|
18
|
+
res ||= System::Activator.create_instance(return_type) if is_value_type
|
19
|
+
res
|
22
20
|
end
|
23
21
|
|
24
22
|
end
|
@@ -29,16 +27,13 @@ module Caricature
|
|
29
27
|
protected
|
30
28
|
|
31
29
|
# deliver the message to the receiving isolation
|
32
|
-
def internal_deliver(mode, method_name, return_type, *args, &b)
|
30
|
+
def internal_deliver(mode, method_name, return_type, *args, &b)
|
31
|
+
res = nil
|
32
|
+
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
33
33
|
exp = expectations.find(method_name, mode, *args)
|
34
|
-
if exp
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
rt = nil
|
39
|
-
rt = System::Activator.create_instance(return_type) if return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
40
|
-
rt
|
41
|
-
end
|
34
|
+
res = exp.execute *args if exp
|
35
|
+
res ||= System::Activator.create_instance(return_type) if is_value_type
|
36
|
+
res
|
42
37
|
end
|
43
38
|
|
44
39
|
end
|
data/lib/caricature/clr.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
load_assembly 'Workarounds, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
|
1
|
+
#IronRuby.load_assembly 'Workarounds, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + "/clr/descriptor"
|
4
4
|
require File.dirname(__FILE__) + "/clr/messenger"
|
@@ -61,7 +61,7 @@ module Caricature
|
|
61
61
|
|
62
62
|
# collects all the members that are defined by this class
|
63
63
|
def initialize_instance_members_for(klass)
|
64
|
-
@instance_members += klass.instance_methods
|
64
|
+
@instance_members += (klass.instance_methods - Object.instance_methods).collect { |mn| MemberDescriptor.new(mn) }
|
65
65
|
end
|
66
66
|
|
67
67
|
# collects all the members that aren't a member of Object.singleton_methods
|
@@ -38,9 +38,10 @@ module Caricature
|
|
38
38
|
# tell the expection which arguments it needs to respond to
|
39
39
|
# there is a magic argument here +any+ which configures
|
40
40
|
# the expectation to respond to any arguments
|
41
|
-
def with(*args)
|
41
|
+
def with(*args, &b)
|
42
42
|
@any_args = args.first.is_a?(Symbol) and args.first == :any
|
43
|
-
@args = args
|
43
|
+
@args = args
|
44
|
+
@callback = b unless b.nil?
|
44
45
|
self
|
45
46
|
end
|
46
47
|
|
@@ -95,12 +96,15 @@ module Caricature
|
|
95
96
|
attr_reader :return_value
|
96
97
|
|
97
98
|
# indicator for the mode to call the super +:before+, +:after+ and +nil+
|
98
|
-
attr_reader :super
|
99
|
+
attr_reader :super
|
100
|
+
|
101
|
+
# contains the callback if one is given
|
102
|
+
attr_reader :callback
|
99
103
|
|
100
104
|
# Initializes a new instance of an expectation
|
101
|
-
def initialize(method_name, args, error_args, return_value, super_mode)
|
102
|
-
@method_name, @args, @error_args, @return_value, @super =
|
103
|
-
method_name, args, error_args, return_value, super_mode
|
105
|
+
def initialize(method_name, args, error_args, return_value, super_mode, callback)
|
106
|
+
@method_name, @args, @error_args, @return_value, @super, @callback =
|
107
|
+
method_name, args, error_args, return_value, super_mode, callback
|
104
108
|
@any_args = true
|
105
109
|
end
|
106
110
|
|
@@ -122,13 +126,19 @@ module Caricature
|
|
122
126
|
# indicates whether super needs to be called somewhere
|
123
127
|
def call_super?
|
124
128
|
!@super.nil?
|
129
|
+
end
|
130
|
+
|
131
|
+
# indicates whether this expecation has a callback it needs to execute
|
132
|
+
def has_callback?
|
133
|
+
!@callback.nil?
|
125
134
|
end
|
126
135
|
|
127
136
|
# executes this expectation with its configuration
|
128
137
|
def execute(*margs)
|
129
138
|
ags = any_args? ? (margs.empty? ? :any : margs) : args
|
130
|
-
actual_raise *@error_args if has_error_args?
|
131
|
-
|
139
|
+
actual_raise *@error_args if has_error_args?
|
140
|
+
callback.call(*ags) if has_callback?
|
141
|
+
return return_value if has_return_value?
|
132
142
|
nil
|
133
143
|
end
|
134
144
|
|
@@ -151,15 +161,15 @@ module Caricature
|
|
151
161
|
# this builder is passed into the block to allow only certain
|
152
162
|
# operations in the block.
|
153
163
|
def initialize(method_name)
|
154
|
-
@method_name, @return_value, @super, @block, @error_args, @args, @any_args =
|
155
|
-
method_name, nil, nil, nil, nil, [], true
|
164
|
+
@method_name, @return_value, @super, @block, @error_args, @args, @any_args, @callback =
|
165
|
+
method_name, nil, nil, nil, nil, [], true, nil
|
156
166
|
end
|
157
167
|
|
158
168
|
|
159
169
|
|
160
170
|
# build up the expectation with the provided arguments
|
161
171
|
def build
|
162
|
-
Expectation.new @method_name, @args, @error_args, @return_value, @super
|
172
|
+
Expectation.new @method_name, @args, @error_args, @return_value, @super, @callback
|
163
173
|
end
|
164
174
|
|
165
175
|
end
|
data/lib/caricature/isolation.rb
CHANGED
@@ -53,7 +53,7 @@ module Caricature
|
|
53
53
|
|
54
54
|
# the real instance of the isolated subject
|
55
55
|
# used to forward calls in partial mocks
|
56
|
-
|
56
|
+
attr_accessor :instance
|
57
57
|
|
58
58
|
# the method call recorder
|
59
59
|
attr_reader :recorder
|
@@ -66,7 +66,8 @@ module Caricature
|
|
66
66
|
@instance = isolator.subject
|
67
67
|
@recorder = context.recorder
|
68
68
|
@messenger = context.messenger
|
69
|
-
@expectations = context.expectations
|
69
|
+
@expectations = context.expectations
|
70
|
+
@proxy = isolator.isolation
|
70
71
|
isolator.isolation.class.instance_variable_set("@___context___", self)
|
71
72
|
end
|
72
73
|
|
@@ -124,7 +125,12 @@ module Caricature
|
|
124
125
|
def internal_create_override(method_name, mode=:instance, &block)
|
125
126
|
builder = ExpectationBuilder.new method_name
|
126
127
|
block.call builder unless block.nil?
|
127
|
-
exp = builder.build
|
128
|
+
exp = builder.build
|
129
|
+
@proxy.class.send((mode == :instance ? :define_method : :define_cmethod), method_name.to_sym, lambda do |*args|
|
130
|
+
b = nil
|
131
|
+
b = Proc.new { yield } if block_given?
|
132
|
+
isolation_context.send_message(method_name, nil, *args, &b)
|
133
|
+
end)
|
128
134
|
expectations.add_expectation exp, mode
|
129
135
|
exp
|
130
136
|
end
|
data/lib/caricature/isolator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'uuidtools'
|
1
3
|
require File.dirname(__FILE__) + '/messenger'
|
2
4
|
require File.dirname(__FILE__) + '/descriptor'
|
3
5
|
|
@@ -134,7 +136,7 @@ module Caricature
|
|
134
136
|
# You can specify constraints in the block
|
135
137
|
#
|
136
138
|
# The most complex configuration you can make currently is one that is constrained by arguments.
|
137
|
-
# This is
|
139
|
+
# This is likely to be extended in the future to allow for more complex verifications.
|
138
140
|
#
|
139
141
|
# Example:
|
140
142
|
#
|
@@ -150,6 +152,14 @@ module Caricature
|
|
150
152
|
# during the course of the test you're running.
|
151
153
|
def did_class_receive?(method_name, &block)
|
152
154
|
self.class.did_receive?(method_name, &block)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Initializes the underlying subject
|
158
|
+
# It expects the constructor parameters if they are needed.
|
159
|
+
def with_subject(*args, &b)
|
160
|
+
isolation_context.instance = self.class.superclass.new *args
|
161
|
+
yield self if block_given?
|
162
|
+
self
|
153
163
|
end
|
154
164
|
|
155
165
|
end
|
@@ -194,7 +204,7 @@ module Caricature
|
|
194
204
|
# Creates the new class name for the isolation
|
195
205
|
def class_name(subj)
|
196
206
|
nm = subj.respond_to?(:class_eval) ? subj.demodulize : subj.class.demodulize
|
197
|
-
@class_name = "#{nm}#{
|
207
|
+
@class_name = "#{nm}#{UUIDTools::UUID.random_create.to_s.gsub /-/, ''}"
|
198
208
|
@class_name
|
199
209
|
end
|
200
210
|
|
@@ -232,7 +242,8 @@ module Caricature
|
|
232
242
|
def initialize(context)
|
233
243
|
super
|
234
244
|
klass = @context.subject.respond_to?(:class_eval) ? @context.subject : @context.subject.class
|
235
|
-
inst = @context.subject.respond_to?(:class_eval) ?
|
245
|
+
inst = @context.subject.respond_to?(:class_eval) ? nil : @context.subject
|
246
|
+
# inst = @context.subject.respond_to?(:class_eval) ? @context.subject.new : @context.subject
|
236
247
|
@descriptor = RubyObjectDescriptor.new klass
|
237
248
|
build_isolation klass, inst
|
238
249
|
end
|
@@ -261,19 +272,24 @@ module Caricature
|
|
261
272
|
mn = mn.name.to_s.to_sym
|
262
273
|
define_method mn do |*args|
|
263
274
|
b = nil
|
264
|
-
b = Proc.new { yield } if block_given?
|
275
|
+
b = Proc.new { yield } if block_given?
|
265
276
|
isolation_context.send_message(mn, nil, *args, &b)
|
266
277
|
end
|
267
|
-
end
|
268
|
-
|
278
|
+
end
|
279
|
+
|
280
|
+
def initialize(*args)
|
281
|
+
self
|
282
|
+
end
|
283
|
+
|
269
284
|
cmembers.each do |mn|
|
270
285
|
mn = mn.name.to_s.to_sym
|
271
|
-
define_cmethod mn do |*args|
|
286
|
+
define_cmethod mn do |*args|
|
272
287
|
b = nil
|
273
|
-
b = Proc.new { yield } if block_given?
|
288
|
+
b = Proc.new { yield } if block_given?
|
274
289
|
isolation_context.send_class_message(mn, nil, *args, &b)
|
275
290
|
end
|
276
|
-
end
|
291
|
+
end
|
292
|
+
|
277
293
|
|
278
294
|
|
279
295
|
end
|
data/lib/caricature/messenger.rb
CHANGED
@@ -41,7 +41,7 @@ module Caricature
|
|
41
41
|
protected
|
42
42
|
|
43
43
|
# implementation of the template method for looking up the expectation and/or returning a value
|
44
|
-
def internal_deliver(mode, method_name, return_type, *args, &b)
|
44
|
+
def internal_deliver(mode, method_name, return_type, *args, &b)
|
45
45
|
exp = expectations.find(method_name, mode, *args)
|
46
46
|
if exp
|
47
47
|
res = instance.__send__(method_name, *args, &b) if exp.super_before?
|
data/lib/caricature.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module Caricature
|
3
4
|
#
|
4
5
|
# module Interception
|
5
6
|
#
|
6
7
|
# end
|
7
8
|
#
|
8
|
-
|
9
|
+
end
|
9
10
|
|
10
|
-
require
|
11
|
-
require
|
11
|
+
require 'core_ext/core_ext'
|
12
|
+
require 'caricature/version'
|
13
|
+
require 'caricature/isolation'
|
14
|
+
require 'caricature/clr' if defined? IRONRUBY_VERSION
|