This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 7a00e65ec33d6d65bdb8b7ae5901965d13abe29b
tree 0afbb6a3f2b921b67b2c99f7d3b26b1ccc99b151
parent 70ef615072b65344e7db35ec1c7ca3045ed484e0
tree 0afbb6a3f2b921b67b2c99f7d3b26b1ccc99b151
parent 70ef615072b65344e7db35ec1c7ca3045ed484e0
object_proxy / test / test_object_proxy.rb
| fec8667a » | JackDanger | 2008-03-05 | 1 | require 'test/unit' | |
| 2 | require File.dirname(__FILE__) + '/../lib/object_proxy' | ||||
| 3 | |||||
| 4 | class OneHundredProxy < ObjectProxy | ||||
| 5 | def initialize | ||||
| 6 | @target = 100 | ||||
| 7 | end | ||||
| 8 | end | ||||
| 9 | |||||
| 10 | class ObjectProxyTest < Test::Unit::TestCase | ||||
| 11 | def test_does_not_respond_to_target | ||||
| 12 | assert_raises(NoMethodError) { ObjectProxy.new('some_value').responds_to?(:target) } | ||||
| 13 | end | ||||
| 14 | |||||
| 15 | def test_has_target_method_that_returns_the_provided_value | ||||
| 16 | assert_equal 'target', ObjectProxy.new('target') | ||||
| 17 | end | ||||
| 18 | |||||
| 19 | def test_target_object_does_not_have_identity_with_initialized_object | ||||
| 20 | object = Object.new | ||||
| 21 | assert !object.equal?(ObjectProxy.new(object)) | ||||
| 22 | end | ||||
| 23 | |||||
| 24 | def test_class_method_is_passed_to_target | ||||
| 25 | assert_equal String, ObjectProxy.new('some value').class | ||||
| 26 | end | ||||
| 27 | |||||
| 28 | def test_send_is_passed_to_target | ||||
| 29 | object = 'ABCDEF' | ||||
| 30 | assert_equal object.send(:length), ObjectProxy.new(object).send(:length) | ||||
| 31 | end | ||||
| 32 | |||||
| 33 | def test_proxy_class_accesses_the_class_of_the_object_proxy | ||||
| 34 | assert_equal ObjectProxy, ObjectProxy.new('value').proxy_class | ||||
| 35 | end | ||||
| 36 | |||||
| 37 | def test_proxy_class_allows_methods_added_to_the_proxy_class | ||||
| 38 | object = 'ABCDEF' | ||||
| 39 | proxy = ObjectProxy.new(object) | ||||
| 40 | proxy.proxy_class.class_eval do | ||||
| 41 | define_method :return_target do | ||||
| 42 | @target | ||||
| 43 | end | ||||
| 44 | end | ||||
| 45 | assert_equal object, proxy.return_target | ||||
| 46 | end | ||||
| 47 | |||||
| 48 | def test_method_missing_errors_are_raised_from_the_target_object | ||||
| 49 | begin | ||||
| 50 | ObjectProxy.new(12345).howzitgoin | ||||
| 51 | rescue => e | ||||
| 52 | assert_equal %Q(undefined method `howzitgoin' for 12345:Fixnum), e.message | ||||
| 53 | end | ||||
| 54 | end | ||||
| 55 | |||||
| 56 | def test_subclass_of_object_proxy_can_set_target_however_it_wants | ||||
| 57 | assert_equal 100, OneHundredProxy.new.target | ||||
| 58 | end | ||||
| 59 | end | ||||







