mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
#has_link? support for checking the href attribute
This commit is contained in:
parent
f2b153016a
commit
b38a4991ee
2 changed files with 24 additions and 7 deletions
|
@ -201,11 +201,14 @@ module Capybara
|
|||
# Checks if the page or current node has a link with the given
|
||||
# text or id.
|
||||
#
|
||||
# @param [String] locator The text or id of a link to check for
|
||||
# @return [Boolean] Whether it exists
|
||||
# @param [String] locator The text or id of a link to check for
|
||||
# @param options
|
||||
# @option options [String] :href The value the href attribute must be
|
||||
# @return [Boolean] Whether it exists
|
||||
#
|
||||
def has_link?(locator)
|
||||
has_xpath?(XPath::HTML.link(locator))
|
||||
def has_link?(locator, options={})
|
||||
options = set_link_options options
|
||||
has_xpath?(XPath::HTML.link(locator, options))
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -213,11 +216,12 @@ module Capybara
|
|||
# Checks if the page or current node has no link with the given
|
||||
# text or id.
|
||||
#
|
||||
# @param [String] locator The text or id of a link to check for
|
||||
# @param (see Capybara::Node::Finders#has_link?)
|
||||
# @return [Boolean] Whether it doesn't exist
|
||||
#
|
||||
def has_no_link?(locator)
|
||||
has_no_xpath?(XPath::HTML.link(locator))
|
||||
def has_no_link?(locator, options={})
|
||||
options = set_link_options options
|
||||
has_no_xpath?(XPath::HTML.link(locator, options))
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -373,6 +377,11 @@ module Capybara
|
|||
def has_no_table?(locator, options={})
|
||||
has_no_xpath?(XPath::HTML.table(locator, options))
|
||||
end
|
||||
|
||||
private
|
||||
def set_link_options(options)
|
||||
String===options ? {:href => options} : options
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,10 +8,14 @@ shared_examples_for "has_link" do
|
|||
it "should be true if the given link is on the page" do
|
||||
@session.should have_link('foo')
|
||||
@session.should have_link('awesome title')
|
||||
@session.should have_link('A link', '/with_simple_html')
|
||||
@session.should have_link('A link', :href => '/with_simple_html')
|
||||
end
|
||||
|
||||
it "should be false if the given link is not on the page" do
|
||||
@session.should_not have_link('monkey')
|
||||
@session.should_not have_link('A link', '/non-existant-href')
|
||||
@session.should_not have_link('A link', :href => '/non-existant-href')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,10 +27,14 @@ shared_examples_for "has_link" do
|
|||
it "should be false if the given link is on the page" do
|
||||
@session.should_not have_no_link('foo')
|
||||
@session.should_not have_no_link('awesome title')
|
||||
@session.should_not have_no_link('A link', '/with_simple_html')
|
||||
@session.should_not have_no_link('A link', :href => '/with_simple_html')
|
||||
end
|
||||
|
||||
it "should be true if the given link is not on the page" do
|
||||
@session.should have_no_link('monkey')
|
||||
@session.should have_no_link('A link', '/non-existant-href')
|
||||
@session.should have_no_link('A link', :href => '/non-existant-href')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue