Sha256: 1635b049b183804020ca8ec651b7efe0ae4395d4d214154c54fc79e459efa0bd

Contents?: true

Size: 1.29 KB

Versions: 49

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

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

  it 'should assert an ancestor using the given locator' do
    el = @session.find(:css, '#ancestor1')
    expect(el).to have_ancestor(:css, '#ancestor2')
  end

  it 'should assert an ancestor even if not parent' do
    el = @session.find(:css, '#child')
    expect(el).to have_ancestor(:css, '#ancestor3')
  end

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

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

    expect do
      expect(el).to have_ancestor(:css, 'div').once
    end.to raise_error(RSpec::Expectations::ExpectationNotMetError)

    expect(el).to have_ancestor(:css, 'div').exactly(3).times
  end
end

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

  it 'should assert no matching ancestor' do
    el = @session.find(:css, '#ancestor1')
    expect(el).to have_no_ancestor(:css, '#child')
    expect(el).to have_no_ancestor(:css, '#ancestor1_sibiling')
    expect(el).not_to have_ancestor(:css, '#child')
    expect(el).not_to have_ancestor(:css, '#ancestor1_sibiling')
  end
end

Version data entries

49 entries across 36 versions & 4 rubygems

Version Path
capybara-3.30.0 lib/capybara/spec/session/has_ancestor_spec.rb
tdiary-5.1.0 vendor/bundle/gems/capybara-3.29.0/lib/capybara/spec/session/has_ancestor_spec.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/spec/session/has_ancestor_spec.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/capybara-3.29.0/lib/capybara/spec/session/has_ancestor_spec.rb
capybara-3.29.0 lib/capybara/spec/session/has_ancestor_spec.rb
capybara-3.28.0 lib/capybara/spec/session/has_ancestor_spec.rb
capybara-3.27.0 lib/capybara/spec/session/has_ancestor_spec.rb
capybara-3.26.0 lib/capybara/spec/session/has_ancestor_spec.rb
capybara-3.25.0 lib/capybara/spec/session/has_ancestor_spec.rb