Sha256: 210c3fc249866d1b25f8e58e4c4afb37919f4148e8299c9190989ac5f8b9aa65

Contents?: true

Size: 934 Bytes

Versions: 14

Compression:

Stored size: 934 Bytes

Contents

require 'spec_helper'

describe NonSharedAccessors do

  context 'Native Class Accessor in Ruby' do

    it 'should explain native behavior (shared class variable)' do
      class A1
        cattr_accessor :value
      end

      class B1 < A1

      end

      expect(A1.value).to be_nil
      expect(B1.value).to be_nil

      A1.value = 2

      expect(A1.value).to eq(2)
      expect(B1.value).to eq(2)

      B1.value = 3

      expect(A1.value).to eq(3)
      expect(B1.value).to eq(3)
    end
  end

  it 'should behave as a separate accessor(separate class valiable)' do

    class A2
      include NonSharedAccessors
      non_shared_cattr_accessor :value
    end

    class B2 < A2

    end

    expect(A2.value).to be_nil
    expect(B2.value).to be_nil

    A2.value = 2

    expect(A2.value).to eq(2)
    expect(B2.value).to eq(nil)

    B2.value = 3

    expect(A2.value).to eq(2)
    expect(B2.value).to eq(3)
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tarvit-helpers-0.0.23 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.22 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.21 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.20 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.19 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.18 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.17 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.16 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.15 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.14 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.13 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.12 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.11 spec/modules/non_shared_accessors_spec.rb
tarvit-helpers-0.0.10 spec/modules/non_shared_accessors_spec.rb