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

- old
+ new

@@ -257,9 +257,30 @@ it 'assigns a defined role to each item in a role player collection' do assert_equal "member show, member show", context.get_member_show end end +describe Surrounded::Context, 'reusing context object' do + let(:user){ User.new("Jim") } + let(:other_user){ User.new("Guille") } + let(:context){ TestContext.new(user, other_user) } + + it 'allows rebinding new players' do + expect(context.access_other_object).must_equal 'Guille' + context.rebind(user: User.new('Amy'), other_user: User.new('Elizabeth')) + expect(context.access_other_object).must_equal 'Elizabeth' + end + + it 'clears internal storage when rebinding' do + originals = context.instance_variables.map{|var| context.instance_variable_get(var) } + context.rebind(user: User.new('Amy'), other_user: User.new('Elizabeth')) + new_ivars = context.instance_variables.map{|var| context.instance_variable_get(var) } + originals.zip(new_ivars).each do |original_ivar, new_ivar| + expect(original_ivar).wont_equal new_ivar + end + end +end + begin class Keyworder extend Surrounded::Context keyword_initialize :this, :that