File: node_wrapper_spec.rb

package info (click to toggle)
ruby-capybara 3.40.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: ruby: 23,988; javascript: 752; makefile: 11
file content (39 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

class NodeWrapper
  def initialize(element); @element = element end
  def to_capybara_node(); @element end
end

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

  it 'should support have_xxx expectations' do
    para = NodeWrapper.new(@session.find(:css, '#first'))
    expect(para).to have_link('ullamco')
  end

  it 'should support within' do
    para = NodeWrapper.new(@session.find(:css, '#first'))
    expect(@session).to have_css('#second')
    @session.within(para) do
      expect(@session).to have_link('ullamco')
      expect(@session).not_to have_css('#second')
    end
  end

  it 'should generate correct errors' do
    para = NodeWrapper.new(@session.find(:css, '#first'))
    expect do
      expect(para).to have_text('Header Class Test One')
    end.to raise_error(/^expected to find text "Header Class Test One" in "Lore/)
    expect do
      expect(para).to have_css('#second')
    end.to raise_error(/^expected to find css "#second" within #<Capybara::Node::Element/)
    expect do
      expect(para).to have_link(href: %r{/without_simple_html})
    end.to raise_error(%r{^expected to find link with href matching /\\/without_simple_html/ within #<Capybara::Node::Element})
  end
end