File: result_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 (65 lines) | stat: -rw-r--r-- 1,235 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
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper'

describe Capybara::Result do
  let :string do
    Capybara.string <<-STRING
      <ul>
        <li>Alpha</li>
        <li>Beta</li>
        <li>Gamma</li>
        <li>Delta</li>
      </ul>
    STRING
  end

  let :result do
    string.all '//li'
  end

  it "has a length" do
    result.length.should == 4
  end

  it "has a first element" do
    result.first.text == 'Alpha'
  end

  it "has a last element" do
    result.last.text == 'Delta'
  end

  it 'can supports values_at method' do
    result.values_at(0, 2).map(&:text).should == %w(Alpha Gamma)
  end

  it "can return an element by its index" do
    result.at(1).text.should == 'Beta'
    result[2].text.should == 'Gamma'
  end

  it "can be mapped" do
    result.map(&:text).should == %w(Alpha Beta Gamma Delta)
  end

  it "can be selected" do
    result.select do |element|
      element.text.include? 't'
    end.length.should == 2
  end

  it "can be reduced" do
    result.reduce('') do |memo, element|
      memo += element.text[0]
    end.should == 'ABGD'
  end

  it 'can be sampled' do
    result.should include(result.sample)
  end

  it 'can be indexed' do
    result.index do |el|
      el.text == 'Gamma'
    end.should == 2
  end
end