test/example_proxy_test.rb in surrounded-0.9.4 vs test/example_proxy_test.rb in surrounded-0.9.5

- old
+ new

@@ -1,8 +1,7 @@ require 'test_helper' -# If you want to use wrappers, here's how you could class ProxyContext extend Surrounded::Context initialize(:admin, :task) @@ -32,14 +31,21 @@ end trigger :admin_missing_method do admin.method_that_does_not_exist end + + trigger :admin_responds? do + admin.respond_to?(:talking_to_others) + end + + trigger :get_admin_method do + admin.method(:talking_to_others) + end end ProxyUser = Class.new do - include Surrounded def initialize(name) @name = name end attr_reader :name end @@ -66,9 +72,27 @@ err = ->{ context.admin_missing_method }.must_raise(NoMethodError) assert_match(/ProxyUser.*name="Jim"/, err.message) end - it 'allows access to other objects in the context' do - assert_equal 'GTD', context.talking + it 'fails access to other objects in the context' do + err = _{ context.talking }.must_raise NameError + assert_match(%r{undefined local variable or method `task'}, err.message) + end + + it 'sets roles to respond to role methods' do + assert context.admin_responds? + end + + it 'is able to grab methods from the object' do + assert_equal :talking_to_others, context.get_admin_method.name + end + + it 'works with frozen and primitive objects' do + context.rebind(admin: "brrr".freeze, task: task) + assert context.get_admin_method + context.rebind(admin: nil, task: task) + assert context.get_admin_method + context.rebind(admin: true, task: task) + assert context.get_admin_method end end