Sha256: 1da56042a2a0c2ff5832471a12b83e2d05e72b5b3dab6564cd66bc31bc517b2e

Contents?: true

Size: 1.07 KB

Versions: 88

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

Capybara::SpecHelper.spec '#match_css?' do
  before do
    @session.visit('/with_html')
    @element = @session.find(:css, 'span', text: '42')
  end

  it 'should be true if the given selector matches the element' do
    expect(@element).to match_css('span')
    expect(@element).to match_css('span.number')
  end

  it 'should be false if the given selector does not match' do
    expect(@element).not_to match_css('div')
    expect(@element).not_to match_css('p a#doesnotexist')
    expect(@element).not_to match_css('p.nosuchclass')
  end

  it 'should accept an optional filter block' do
    # This would be better done with
    expect(@element).to match_css('span') { |el| el[:class] == 'number' }
    expect(@element).not_to match_css('span') { |el| el[:class] == 'not_number' }
  end

  it 'should work with root element found via ancestor' do
    el = @session.find(:css, 'body').find(:xpath, '..')
    expect(el).to match_css('html')
    expect { expect(el).to not_match_css('html') }.to raise_exception(RSpec::Expectations::ExpectationNotMetError)
  end
end

Version data entries

88 entries across 75 versions & 5 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/capybara-3.40.0/lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.40.0 lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.39.2 lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.39.1 lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.39.0 lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.38.0 lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.37.1 lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.37.0 lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/capybara-3.36.0/lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/element/match_css_spec.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/spec/session/element/match_css_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/spec/session/element/match_css_spec.rb
capybara-3.36.0 lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/spec/session/element/match_css_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/element/match_css_spec.rb