Sha256: ccaaf673058fe5c0d573b077267c88311b3e2c24fa2dfa33561cd79d269acf5d

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Hexp::Node, 'attr' do
  subject    { hexp.attr(*args)      }
  let(:hexp) { H[:div, class: 'foo'] }

  context 'with a single string argument' do
    let(:args) { ['class'] }

    it 'should return the attribute value by that name' do
      expect(subject).to eq('foo')
    end
  end

  context 'with a single symbol argument' do
    let(:args) { [:class] }

    it 'should return the attribute value by that name' do
      expect(subject).to eq('foo')
    end
  end

  context 'with two argument' do
    let(:args) { ['data-id', '7'] }

    it 'should return a new Hexp::Node' do
      expect(subject).to be_instance_of(Hexp::Node)
    end

    it 'should set the attribute value' do
      expect(subject.attributes['data-id']).to eq('7')
    end

    it 'should leave other attributes untouched' do
      expect(subject.attributes['class']).to eq('foo')
    end

    context 'with a nil value' do
      let(:args) { ['class', nil] }

      it 'should unset the attribute' do
        expect(subject.attributes).to eq({})
      end
    end
  end

  context 'with too many arguments' do
    let(:args) { ['class', 'baz', 'bar'] }

    it 'should raise an ArgumentError' do
      expect{ subject }.to raise_error(ArgumentError)
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hexp-0.4.6 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.5 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.4 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.3 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.2 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.1 spec/unit/hexp/node/attr_spec.rb
hexp-0.4.0.beta1 spec/unit/hexp/node/attr_spec.rb
hexp-0.3.3 spec/unit/hexp/node/attr_spec.rb
hexp-0.3.2 spec/unit/hexp/node/attr_spec.rb
hexp-0.3.1 spec/unit/hexp/node/attr_spec.rb
hexp-0.3.0 spec/unit/hexp/node/attr_spec.rb
hexp-0.2.0 spec/unit/hexp/node/attr_spec.rb