2012-08-09 20:38:07 -04:00
|
|
|
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
|
|
|
|
|
2013-10-29 16:43:11 -04:00
|
|
|
it 'can supports values_at method' do
|
|
|
|
result.values_at(0, 2).map(&:text).should == %w(Alpha Gamma)
|
|
|
|
end
|
|
|
|
|
2012-08-09 20:38:07 -04:00
|
|
|
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
|
2013-09-16 07:19:06 -04:00
|
|
|
|
|
|
|
it 'can be sampled' do
|
|
|
|
result.should include(result.sample)
|
|
|
|
end
|
2013-10-29 16:43:11 -04:00
|
|
|
|
|
|
|
it 'can be indexed' do
|
|
|
|
result.index do |el|
|
|
|
|
el.text == 'Gamma'
|
|
|
|
end.should == 2
|
|
|
|
end
|
2012-08-09 20:38:07 -04:00
|
|
|
end
|