File: text_spec.rb

package info (click to toggle)
ruby-capybara 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 948 kB
  • ctags: 516
  • sloc: ruby: 7,998; makefile: 4
file content (53 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Capybara::SpecHelper.spec '#text' do
  it "should print the text of the page" do
    @session.visit('/with_simple_html')
    @session.text.should == 'Bar'
  end

  it "ignores invisible text by default" do
    @session.visit('/with_html')
    @session.find(:id, "hidden-text").text.should == 'Some of this text is'
  end

  it "shows invisible text if `:all` given" do
    @session.visit('/with_html')
    @session.find(:id, "hidden-text").text(:all).should == 'Some of this text is hidden!'
  end

  it "ignores invisible text if `:visible` given" do
    Capybara.ignore_hidden_elements = false
    @session.visit('/with_html')
    @session.find(:id, "hidden-text").text(:visible).should == 'Some of this text is'
  end

  it "ignores invisible text if `Capybara.ignore_hidden_elements = true`" do
    @session.visit('/with_html')
    @session.find(:id, "hidden-text").text.should == 'Some of this text is'
    Capybara.ignore_hidden_elements = false
    @session.find(:id, "hidden-text").text.should == 'Some of this text is hidden!'
  end

  it "ignores invisible text if `Capybara.visible_text_only = true`" do
    @session.visit('/with_html')
    Capybara.visible_text_only = true
    @session.find(:id, "hidden-text").text.should == 'Some of this text is'
    Capybara.ignore_hidden_elements = false
    @session.find(:id, "hidden-text").text.should == 'Some of this text is'
  end

  context "with css as default selector" do
    before { Capybara.default_selector = :css }
    it "should print the text of the page" do
      @session.visit('/with_simple_html')
      @session.text.should == 'Bar'
    end
    after { Capybara.default_selector = :xpath }
  end

  it "should strip whitespace" do
    @session.visit('/with_html')
    n = @session.find(:css, '#second')
    @session.find(:css, '#second').text.should =~ \
      /\ADuis aute .* text with whitespace .* est laborum\.\z/
  end
end