Sha256: 26a8edd7c11efff5eac9598976991b1550b242938ba5f0cf77564bee8db5bb61

Contents?: true

Size: 1.47 KB

Versions: 58

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

Capybara::SpecHelper.spec '#have_sibling' do
  before do
    @session.visit('/with_html')
  end

  it 'should assert a prior sibling element using the given locator' do
    el = @session.find(:css, '#mid_sibling')
    expect(el).to have_sibling(:css, '#pre_sibling')
  end

  it 'should assert a following sibling element using the given locator' do
    el = @session.find(:css, '#mid_sibling')
    expect(el).to have_sibling(:css, '#post_sibling')
  end

  it 'should not raise an error if there are multiple matches' do
    el = @session.find(:css, '#mid_sibling')
    expect(el).to have_sibling(:css, 'div')
  end

  it 'should allow counts to be specified' do
    el = @session.find(:css, '#mid_sibling')

    expect(el).to have_sibling(:css, 'div').exactly(2).times
    expect do
      expect(el).to have_sibling(:css, 'div').once
    end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
  end
end

Capybara::SpecHelper.spec '#have_no_sibling' do
  before do
    @session.visit('/with_html')
  end

  it 'should assert no matching sibling' do
    el = @session.find(:css, '#mid_sibling')
    expect(el).to have_no_sibling(:css, '#not_a_sibling')
    expect(el).not_to have_sibling(:css, '#not_a_sibling')
  end

  it 'should raise if there are matching siblings' do
    el = @session.find(:css, '#mid_sibling')
    expect do
      expect(el).to have_no_sibling(:css, '#pre_sibling')
    end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
  end
end

Version data entries

58 entries across 45 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/has_sibling_spec.rb
capybara-3.40.0 lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.39.2 lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.39.1 lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.39.0 lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.38.0 lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/capybara-3.37.1/lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.37.1 lib/capybara/spec/session/has_sibling_spec.rb
capybara-3.37.0 lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/capybara-3.36.0/lib/capybara/spec/session/has_sibling_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/has_sibling_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/has_sibling_spec.rb
capybara-3.36.0 lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/has_sibling_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/spec/session/has_sibling_spec.rb