public
Rubygem
Description: ObjectProxy provides a proxied interface to Ruby objects. It lets you add methods to objects that don't normally support them.
Homepage: http://6brand.com
Clone URL: git://github.com/JackDanger/object_proxy.git
Search Repo:
looks like my clever rename broke the 'rake test' task.
Jack Danger Canty (author)
Thu Mar 06 05:47:33 -0800 2008
commit  cad9db585a5f9da17a3878d44e6b37dc30acc160
tree    83071e4b9d6741090ecb91f6b0b952fc3ac9d1c3
parent  1713af91d8eed42f75f2f9cd9421af5cb9360d05
...
1
2
3
4
5
6
7
8
9
10
...
 
 
 
 
 
 
 
 
 
 
0
@@ -1,11 +1 @@
0
-require 'test/unit'
0
-require File.dirname(__FILE__) + '/../lib/object_proxy'
0
-
0
-class ObjectProxySafeHashTest < Test::Unit::TestCase
0
- def test_object_proxy_identifies_as_target_for_hash_lookup
0
- object = 'a string'
0
- hash = {object => true}
0
- assert hash[ObjectProxy.new(object)]
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,60 +1 @@
0
-require 'test/unit'
0
-require File.dirname(__FILE__) + '/../lib/object_proxy'
0
-
0
-class OneHundredProxy < ObjectProxy
0
- def initialize
0
- @target = 100
0
- end
0
-end
0
-
0
-class ObjectProxyTest < Test::Unit::TestCase
0
- def test_does_not_respond_to_target
0
- assert_raises(NoMethodError) { ObjectProxy.new('some_value').responds_to?(:target) }
0
- end
0
-
0
- def test_has_target_method_that_returns_the_provided_value
0
- assert_equal 'target', ObjectProxy.new('target')
0
- end
0
-
0
- def test_target_object_does_not_have_identity_with_initialized_object
0
- object = Object.new
0
- assert !object.equal?(ObjectProxy.new(object))
0
- end
0
-
0
- def test_class_method_is_passed_to_target
0
- assert_equal String, ObjectProxy.new('some value').class
0
- end
0
-
0
- def test_send_is_passed_to_target
0
- object = 'ABCDEF'
0
- assert_equal object.send(:length), ObjectProxy.new(object).send(:length)
0
- end
0
-
0
- def test_proxy_class_accesses_the_class_of_the_object_proxy
0
- assert_equal ObjectProxy, ObjectProxy.new('value').proxy_class
0
- end
0
-
0
- def test_proxy_class_allows_methods_added_to_the_proxy_class
0
- object = 'ABCDEF'
0
- proxy = ObjectProxy.new(object)
0
- proxy.proxy_class.class_eval do
0
- define_method :return_target do
0
- @target
0
- end
0
- end
0
- assert_equal object, proxy.return_target
0
- end
0
-
0
- def test_method_missing_errors_are_raised_from_the_target_object
0
- begin
0
- ObjectProxy.new(12345).howzitgoin
0
- rescue => e
0
- assert_equal %Q(undefined method `howzitgoin' for 12345:Fixnum), e.message
0
- end
0
- end
0
-
0
- def test_subclass_of_object_proxy_can_set_target_however_it_wants
0
- assert_equal 100, OneHundredProxy.new.target
0
- end
0
-end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
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
0
@@ -1 +1,60 @@
0
+require 'test/unit'
0
+require File.dirname(__FILE__) + '/../lib/object_proxy'
0
+
0
+class OneHundredProxy < ObjectProxy
0
+ def initialize
0
+ @target = 100
0
+ end
0
+end
0
+
0
+class ObjectProxyTest < Test::Unit::TestCase
0
+ def test_does_not_respond_to_target
0
+ assert_raises(NoMethodError) { ObjectProxy.new('some_value').responds_to?(:target) }
0
+ end
0
+
0
+ def test_has_target_method_that_returns_the_provided_value
0
+ assert_equal 'target', ObjectProxy.new('target')
0
+ end
0
+
0
+ def test_target_object_does_not_have_identity_with_initialized_object
0
+ object = Object.new
0
+ assert !object.equal?(ObjectProxy.new(object))
0
+ end
0
+
0
+ def test_class_method_is_passed_to_target
0
+ assert_equal String, ObjectProxy.new('some value').class
0
+ end
0
+
0
+ def test_send_is_passed_to_target
0
+ object = 'ABCDEF'
0
+ assert_equal object.send(:length), ObjectProxy.new(object).send(:length)
0
+ end
0
+
0
+ def test_proxy_class_accesses_the_class_of_the_object_proxy
0
+ assert_equal ObjectProxy, ObjectProxy.new('value').proxy_class
0
+ end
0
+
0
+ def test_proxy_class_allows_methods_added_to_the_proxy_class
0
+ object = 'ABCDEF'
0
+ proxy = ObjectProxy.new(object)
0
+ proxy.proxy_class.class_eval do
0
+ define_method :return_target do
0
+ @target
0
+ end
0
+ end
0
+ assert_equal object, proxy.return_target
0
+ end
0
+
0
+ def test_method_missing_errors_are_raised_from_the_target_object
0
+ begin
0
+ ObjectProxy.new(12345).howzitgoin
0
+ rescue => e
0
+ assert_equal %Q(undefined method `howzitgoin' for 12345:Fixnum), e.message
0
+ end
0
+ end
0
+
0
+ def test_subclass_of_object_proxy_can_set_target_however_it_wants
0
+ assert_equal 100, OneHundredProxy.new.target
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1 +1,11 @@
0
+require 'test/unit'
0
+require File.dirname(__FILE__) + '/../lib/object_proxy'
0
+
0
+class ObjectProxySafeHashTest < Test::Unit::TestCase
0
+ def test_object_proxy_identifies_as_target_for_hash_lookup
0
+ object = 'a string'
0
+ hash = {object => true}
0
+ assert hash[ObjectProxy.new(object)]
0
+ end
0
+end

Comments

    No one has commented yet.