Sha256: 7dc1845cdda104f11e8f33ad6089dffd10192414078b8358c8c636c77965ffba

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

require 'test_helper'

describe Surrounded::Context, 'reusing context object' do
  let(:user){ User.new("Jim") }
  let(:other_user){ User.new("Guille") }
  let(:context){ TestContext.new(user: user, other_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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
surrounded-1.1.0 test/context_reuse_test.rb
surrounded-1.0.0 test/context_reuse_test.rb