2009-12-15 14:58:51 -05:00
|
|
|
module ClickLinkSpec
|
|
|
|
shared_examples_for "click_link" do
|
|
|
|
describe '#click_link' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with id given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('foo')
|
|
|
|
@session.body.should include('Another World')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with text given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('labore')
|
2010-01-01 17:58:59 -05:00
|
|
|
@session.body.should include('Bar')
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-11 15:18:32 -05:00
|
|
|
|
|
|
|
it "should accept partial matches" do
|
|
|
|
@session.click_link('abo')
|
|
|
|
@session.body.should include('Bar')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prefer exact matches over partial matches" do
|
|
|
|
@session.click_link('A link')
|
|
|
|
@session.body.should include('Bar')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with title given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('awesome title')
|
2010-01-01 17:58:59 -05:00
|
|
|
@session.body.should include('Bar')
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-11 15:18:32 -05:00
|
|
|
|
|
|
|
it "should accept partial matches" do
|
|
|
|
@session.click_link('some tit')
|
|
|
|
@session.body.should include('Bar')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prefer exact matches over partial matches" do
|
|
|
|
@session.click_link('a fine link')
|
|
|
|
@session.body.should include('Bar')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
running do
|
|
|
|
@session.click_link('does not exist')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should follow redirects" do
|
|
|
|
@session.click_link('Redirect')
|
|
|
|
@session.body.should include('You landed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|