Sha256: da32f8ebd94365a56079dabed0fff5e60461e67d57ee26aad54b7d7ecfbb611b

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe Hexp::CssSelector::SimpleSequence do
  context 'with a single element member' do
    let(:sequence) { described_class[Hexp::CssSelector::Element.new('div')] }

    it 'should match when the element has the same tag name' do
      expect(sequence.matches?(H[:div])).to be_true
    end

    it 'should not match when the tag name differs' do
      expect(sequence.matches?(H[:span])).to be_false
    end
  end

  context 'with a single class member' do
    let(:sequence) { described_class[Hexp::CssSelector::Class.new('mega')] }

    it 'should match when the element has a class by that name' do
      expect(sequence.matches?(H[:div, class: 'mega'])).to be_true
    end

    it 'should not match when the element has no classes' do
      expect(sequence.matches?(H[:span])).to be_false
    end

    it 'should not match when the element has no classes by that name' do
      expect(sequence.matches?(H[:span, class: 'megalopolis'])).to be_false
    end
  end

  context 'with an element and class' do
    let(:sequence) do described_class[
        Hexp::CssSelector::Element.new('div'),
        Hexp::CssSelector::Class.new('mega')
      ]
    end

    it 'should match if all parts are satisfied' do
      expect(sequence.matches?(H[:div, class: 'mega'])).to be_true
    end

    it 'should not match if one parts is not satisfied' do
      expect(sequence.matches?(H[:div, class: 'foo'])).to be_false
      expect(sequence.matches?(H[:span, class: 'mega'])).to be_false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hexp-0.3.3 spec/unit/hexp/css_selector/simple_sequence_spec.rb
hexp-0.3.2 spec/unit/hexp/css_selector/simple_sequence_spec.rb
hexp-0.3.1 spec/unit/hexp/css_selector/simple_sequence_spec.rb
hexp-0.3.0 spec/unit/hexp/css_selector/simple_sequence_spec.rb
hexp-0.2.0 spec/unit/hexp/css_selector/simple_sequence_spec.rb