Sha256: 702772e137dab27909788014ec94a16374a0e9144ac37977419998cbcdd859f5

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

describe "Kernel#instance_variables" do
  context 'for nil' do
    it 'returns blank array' do
      expect(nil.instance_variables).to eq([])
    end
  end

  context 'for string' do
    it 'returns blank array' do
      expect(''.instance_variables).to eq([])
    end
  end

  context 'for hash' do
    it 'returns blank array' do
      expect({}.instance_variables).to eq([])
    end
  end

  context 'for object' do
    it 'returns blank array' do
      expect(Object.new.instance_variables).to eq([])
    end
  end

  context 'cloned object' do
    it 'returns same vars as source object' do
      object = Object.new
      expect(object.clone.instance_variables).to eq(object.instance_variables)
    end
  end

  context 'for object with js keyword as instance variables' do
    reserved_keywords = %w(
      @constructor
      @displayName
      @__proto__
      @__parent__
      @__noSuchMethod__
      @__count__
      @hasOwnProperty
      @valueOf
    )

    reserved_keywords.each do |ivar|
      context "#{ivar} as instance variable name" do
        it "returns non-escaped #{ivar} in instance_variables list" do
          obj = Object.new
          obj.instance_variable_set(ivar, 'value')

          expect(obj.instance_variables).to eq([ivar])
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-0.9.4 spec/opal/core/kernel/instance_variables_spec.rb
opal-0.9.3 spec/opal/core/kernel/instance_variables_spec.rb
opal-0.9.2 spec/opal/core/kernel/instance_variables_spec.rb
opal-0.9.0 spec/opal/core/kernel/instance_variables_spec.rb
opal-0.9.0.rc1 spec/opal/core/kernel/instance_variables_spec.rb