Sha256: 88fe56cdd576a3c230d94b260b09b8d120d4c21c2f96ac92a8799d006da2198b

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Capybara::Selector::CSS::Splitter do
  let :splitter do
    described_class.new
  end

  context 'split not needed' do
    it 'normal CSS selector' do
      css = 'div[id="abc"]'
      expect(splitter.split(css)).to eq [css]
    end

    it 'comma in strings' do
      css = 'div[id="a,bc"]'
      expect(splitter.split(css)).to eq [css]
    end

    it 'comma in pseudo-selector' do
      css = 'div.class1:not(.class1, .class2)'
      expect(splitter.split(css)).to eq [css]
    end
  end

  context 'split needed' do
    it 'root level comma' do
      css = 'div.class1, span, p.class2'
      expect(splitter.split(css)).to eq ['div.class1', 'span', 'p.class2']
    end

    it 'root level comma when quotes and pseudo selectors' do
      css = 'div.class1[id="abc\\"def,ghi"]:not(.class3, .class4), span[id=\'a"c\\\'de\'], section, #abc\\,def'
      expect(splitter.split(css)).to eq ['div.class1[id="abc\\"def,ghi"]:not(.class3, .class4)', 'span[id=\'a"c\\\'de\']', 'section', '#abc\\,def']
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/capybara-3.40.0/spec/css_splitter_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/capybara-3.40.0/spec/css_splitter_spec.rb
capybara-3.40.0 spec/css_splitter_spec.rb
capybara-3.39.2 spec/css_splitter_spec.rb
capybara-3.39.1 spec/css_splitter_spec.rb
capybara-3.39.0 spec/css_splitter_spec.rb