proxies 0.1.0 → 0.1.1
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/VERSION +1 -1
- data/lib/proxies/method_proxy.rb +1 -1
- data/lib/proxies/object_proxy.rb +2 -2
- data/proxies.gemspec +1 -1
- data/test/test_method_proxy_target.rb +21 -6
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
data/lib/proxies/method_proxy.rb
CHANGED
data/lib/proxies/object_proxy.rb
CHANGED
|
@@ -33,9 +33,9 @@ module Proxies
|
|
|
33
33
|
@target = target
|
|
34
34
|
@owner = options[:owner] if options.key?(:owner)
|
|
35
35
|
|
|
36
|
-
extends = Array(options[:extend])
|
|
36
|
+
extends = ::Kernel.Array(options[:extend])
|
|
37
37
|
extends << ::Module.new(&block)
|
|
38
|
-
extends << ObjectProxyOwner if defined?(@owner)
|
|
38
|
+
extends << ::Proxies::ObjectProxyOwner if defined?(@owner)
|
|
39
39
|
extends.each { |m| m.send(:extend_object, self) }
|
|
40
40
|
end
|
|
41
41
|
|
data/proxies.gemspec
CHANGED
|
@@ -4,36 +4,51 @@ class TestMethodProxyTarget < Test::Unit::TestCase
|
|
|
4
4
|
def setup
|
|
5
5
|
@target = "target"
|
|
6
6
|
@object = mock
|
|
7
|
-
@object.expects(:target_method).once.returns(@target)
|
|
8
|
-
@proxy = MethodProxy.new(@object, :target_method) do
|
|
9
|
-
def length_plus_one
|
|
10
|
-
proxy_target.length + 1
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
7
|
end
|
|
14
8
|
|
|
15
9
|
test "non-existing proxy method call is passed to the target" do
|
|
10
|
+
@object.expects(:target_method).once.returns(@target)
|
|
11
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
16
12
|
assert_equal @target.length, @proxy.length
|
|
17
13
|
end
|
|
18
14
|
|
|
19
15
|
test "proxy method returns correct result" do
|
|
16
|
+
@object.expects(:target_method).once.returns(@target)
|
|
17
|
+
@proxy = MethodProxy.new(@object, :target_method) do
|
|
18
|
+
def length_plus_one
|
|
19
|
+
proxy_target.length + 1
|
|
20
|
+
end
|
|
21
|
+
end
|
|
20
22
|
assert_equal @target.length + 1, @proxy.length_plus_one
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
test "object_id method call is passed to proxy target" do
|
|
26
|
+
@object.expects(:target_method).once.returns(@target)
|
|
27
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
24
28
|
assert_equal @target.object_id, @proxy.object_id
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
test "send method call is passed to proxy target" do
|
|
32
|
+
@object.expects(:target_method).once.returns(@target)
|
|
33
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
28
34
|
assert_equal @target.send(:length), @proxy.send(:length)
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
test "== method is passed to proxy_target" do
|
|
38
|
+
@object.expects(:target_method).once.returns(@target)
|
|
39
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
32
40
|
assert @target == @proxy
|
|
33
41
|
assert @proxy == @target
|
|
34
42
|
end
|
|
35
43
|
|
|
36
44
|
test "equal? method is passed to proxy_target" do
|
|
45
|
+
@object.expects(:target_method).once.returns(@target)
|
|
46
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
37
47
|
assert @proxy.equal?(@target)
|
|
38
48
|
end
|
|
49
|
+
|
|
50
|
+
test "target_method is not called if not needed" do
|
|
51
|
+
@proxy = MethodProxy.new(@object, :target_method)
|
|
52
|
+
assert_equal @object, @proxy.proxy_owner
|
|
53
|
+
end
|
|
39
54
|
end
|