Rename clicks_link and clicks_link_within to click_link and click_link_within
This commit is contained in:
parent
ea193e15d2
commit
24ac5d3fb7
@ -102,7 +102,7 @@ module Webrat
|
||||
# Issues a request for the URL pointed to by a link on the current page,
|
||||
# follows any redirects, and verifies the final page load was successful.
|
||||
#
|
||||
# clicks_link has very basic support for detecting Rails-generated
|
||||
# click_link has very basic support for detecting Rails-generated
|
||||
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
||||
# CSRF authenticity tokens if they are present.
|
||||
#
|
||||
@ -112,16 +112,16 @@ module Webrat
|
||||
# for making the link request
|
||||
#
|
||||
# Example:
|
||||
# clicks_link "Sign up"
|
||||
# click_link "Sign up"
|
||||
#
|
||||
# clicks_link "Sign up", :javascript => false
|
||||
# click_link "Sign up", :javascript => false
|
||||
#
|
||||
# clicks_link "Sign up", :method => :put
|
||||
def clicks_link(link_text, options = {})
|
||||
# click_link "Sign up", :method => :put
|
||||
def click_link(link_text, options = {})
|
||||
find_link(link_text).click(options)
|
||||
end
|
||||
|
||||
alias_method :click_link, :clicks_link
|
||||
alias_method :clicks_link, :click_link
|
||||
|
||||
# Verifies that a submit button exists for the form, then submits the form, follows
|
||||
# any redirects, and verifies the final page was successful.
|
||||
|
@ -117,17 +117,17 @@ module Webrat
|
||||
alias_method :reload, :reloads
|
||||
|
||||
|
||||
# Works like clicks_link, but only looks for the link text within a given selector
|
||||
# Works like click_link, but only looks for the link text within a given selector
|
||||
#
|
||||
# Example:
|
||||
# clicks_link_within "#user_12", "Vote"
|
||||
def clicks_link_within(selector, link_text)
|
||||
# click_link_within "#user_12", "Vote"
|
||||
def click_link_within(selector, link_text)
|
||||
within(selector) do |scope|
|
||||
scope.clicks_link(link_text)
|
||||
scope.click_link(link_text)
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :click_link_within, :clicks_link_within
|
||||
alias_method :clicks_link_within, :click_link_within
|
||||
|
||||
def within(selector)
|
||||
yield Scope.new(self, response_body, selector)
|
||||
|
@ -37,17 +37,20 @@ module Webrat
|
||||
|
||||
alias_method :clicks_button, :click_button
|
||||
|
||||
def clicks_link(link_text_or_regexp, options = {})
|
||||
def click_link(link_text_or_regexp, options = {})
|
||||
pattern = adjust_if_regexp(link_text_or_regexp)
|
||||
@selenium.click("webratlink=#{pattern}")
|
||||
wait_for_result(options[:wait])
|
||||
end
|
||||
alias_method :click_link, :clicks_link
|
||||
|
||||
def clicks_link_within(selector, link_text, options = {})
|
||||
alias_method :clicks_link, :click_link
|
||||
|
||||
def click_link_within(selector, link_text, options = {})
|
||||
@selenium.click("webratlinkwithin=#{selector}|#{link_text}")
|
||||
wait_for_result(options[:wait])
|
||||
end
|
||||
|
||||
alias_method :clicks_link_within, :click_link_within
|
||||
|
||||
def wait_for_result(wait_type)
|
||||
if wait_type == :ajax
|
||||
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
||||
|
||||
describe "clicks_link" do
|
||||
describe "click_link" do
|
||||
before do
|
||||
@session = Webrat::TestSession.new
|
||||
end
|
||||
@ -10,7 +10,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
@session.click_link "Link text"
|
||||
end
|
||||
|
||||
it "should click get links" do
|
||||
@ -18,7 +18,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link "Link text", :method => :get
|
||||
@session.click_link "Link text", :method => :get
|
||||
end
|
||||
|
||||
it "should click delete links" do
|
||||
@ -26,7 +26,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:delete).with("/page", {})
|
||||
@session.clicks_link "Link text", :method => :delete
|
||||
@session.click_link "Link text", :method => :delete
|
||||
end
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:post).with("/page", {})
|
||||
@session.clicks_link "Link text", :method => :post
|
||||
@session.click_link "Link text", :method => :post
|
||||
end
|
||||
|
||||
it "should click put links" do
|
||||
@ -43,7 +43,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:put).with("/page", {})
|
||||
@session.clicks_link "Link text", :method => :put
|
||||
@session.click_link "Link text", :method => :put
|
||||
end
|
||||
|
||||
it "should click links by regexp" do
|
||||
@ -51,7 +51,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link /link [a-z]/i
|
||||
@session.click_link /link [a-z]/i
|
||||
end
|
||||
|
||||
it "should click rails javascript links with authenticity tokens" do
|
||||
@ -70,7 +70,7 @@ describe "clicks_link" do
|
||||
return false;">Posts</a>
|
||||
EOS
|
||||
@session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
|
||||
@session.clicks_link "Posts"
|
||||
@session.click_link "Posts"
|
||||
end
|
||||
|
||||
it "should click rails javascript delete links" do
|
||||
@ -89,7 +89,7 @@ describe "clicks_link" do
|
||||
return false;">Delete</a>
|
||||
EOS
|
||||
@session.should_receive(:delete).with("/posts/1", {})
|
||||
@session.clicks_link "Delete"
|
||||
@session.click_link "Delete"
|
||||
end
|
||||
|
||||
it "should click rails javascript post links" do
|
||||
@ -103,7 +103,7 @@ describe "clicks_link" do
|
||||
return false;">Posts</a>
|
||||
EOS
|
||||
@session.should_receive(:post).with("/posts", {})
|
||||
@session.clicks_link "Posts"
|
||||
@session.click_link "Posts"
|
||||
end
|
||||
|
||||
it "should click rails javascript post links without javascript" do
|
||||
@ -117,7 +117,7 @@ describe "clicks_link" do
|
||||
return false;">Posts</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/posts", {})
|
||||
@session.clicks_link "Posts", :javascript => false
|
||||
@session.click_link "Posts", :javascript => false
|
||||
end
|
||||
|
||||
it "should click rails javascript put links" do
|
||||
@ -136,7 +136,7 @@ describe "clicks_link" do
|
||||
return false;">Put</a></h2>
|
||||
EOS
|
||||
@session.should_receive(:put).with("/posts", {})
|
||||
@session.clicks_link "Put"
|
||||
@session.click_link "Put"
|
||||
end
|
||||
|
||||
it "should fail if the javascript link doesn't have a value for the _method input" do
|
||||
@ -155,7 +155,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
|
||||
lambda {
|
||||
@session.clicks_link "Link"
|
||||
@session.click_link "Link"
|
||||
}.should raise_error
|
||||
end
|
||||
|
||||
@ -164,7 +164,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.response_code = 501
|
||||
lambda { @session.clicks_link "Link text" }.should raise_error
|
||||
lambda { @session.click_link "Link text" }.should raise_error
|
||||
end
|
||||
|
||||
[200, 300, 400, 499].each do |status|
|
||||
@ -173,7 +173,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.response_code = status
|
||||
lambda { @session.clicks_link "Link text" }.should_not raise_error
|
||||
lambda { @session.click_link "Link text" }.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
@ -183,7 +183,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
|
||||
lambda {
|
||||
@session.clicks_link "Missing link"
|
||||
@session.click_link "Missing link"
|
||||
}.should raise_error
|
||||
end
|
||||
|
||||
@ -192,7 +192,7 @@ describe "clicks_link" do
|
||||
<a href="/page">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link "LINK TEXT"
|
||||
@session.click_link "LINK TEXT"
|
||||
end
|
||||
|
||||
it "should match link substrings" do
|
||||
@ -200,7 +200,7 @@ describe "clicks_link" do
|
||||
<a href="/page">This is some cool link text, isn't it?</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
@session.click_link "Link text"
|
||||
end
|
||||
|
||||
it "should work with elements in the link" do
|
||||
@ -208,7 +208,7 @@ describe "clicks_link" do
|
||||
<a href="/page"><span>Link text</span></a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page", {})
|
||||
@session.clicks_link "Link text"
|
||||
@session.click_link "Link text"
|
||||
end
|
||||
|
||||
it "should match the first matching link" do
|
||||
@ -217,7 +217,7 @@ describe "clicks_link" do
|
||||
<a href="/page2">Link text</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page1", {})
|
||||
@session.clicks_link "Link text"
|
||||
@session.click_link "Link text"
|
||||
end
|
||||
|
||||
it "should choose the shortest link text match" do
|
||||
@ -227,7 +227,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
|
||||
@session.should_receive(:get).with("/page2", {})
|
||||
@session.clicks_link "Link"
|
||||
@session.click_link "Link"
|
||||
end
|
||||
|
||||
it "should treat non-breaking spaces as spaces" do
|
||||
@ -236,7 +236,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
|
||||
@session.should_receive(:get).with("/page1", {})
|
||||
@session.clicks_link "This is a link"
|
||||
@session.click_link "This is a link"
|
||||
end
|
||||
|
||||
it "should click link within a selector" do
|
||||
@ -248,7 +248,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
|
||||
@session.should_receive(:get).with("/page2", {})
|
||||
@session.clicks_link_within "#container", "Link"
|
||||
@session.click_link_within "#container", "Link"
|
||||
end
|
||||
|
||||
it "should not make request when link is local anchor" do
|
||||
@ -257,7 +257,7 @@ describe "clicks_link" do
|
||||
EOS
|
||||
# Don't know why @session.should_receive(:get).never doesn't work here
|
||||
@session.should_receive(:send).with('get_via_redirect', '#section-1', {}).never
|
||||
@session.clicks_link "Jump to Section 1"
|
||||
@session.click_link "Jump to Section 1"
|
||||
end
|
||||
|
||||
it "should follow relative links" do
|
||||
@ -266,7 +266,7 @@ describe "clicks_link" do
|
||||
<a href="sub">Jump to sub page</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page/sub", {})
|
||||
@session.clicks_link "Jump to sub page"
|
||||
@session.click_link "Jump to sub page"
|
||||
end
|
||||
|
||||
it "should follow fully qualified local links" do
|
||||
@ -274,7 +274,7 @@ describe "clicks_link" do
|
||||
<a href="http://www.example.com/page/sub">Jump to sub page</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("http://www.example.com/page/sub", {})
|
||||
@session.clicks_link "Jump to sub page"
|
||||
@session.click_link "Jump to sub page"
|
||||
end
|
||||
|
||||
it "should follow query parameters" do
|
||||
@ -283,6 +283,6 @@ describe "clicks_link" do
|
||||
<a href="?foo=bar">Jump to foo bar</a>
|
||||
EOS
|
||||
@session.should_receive(:get).with("/page?foo=bar", {})
|
||||
@session.clicks_link "Jump to foo bar"
|
||||
@session.click_link "Jump to foo bar"
|
||||
end
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ describe "within" do
|
||||
|
||||
@session.should_receive(:get).with("/page2", {})
|
||||
@session.within "#container" do |scope|
|
||||
scope.clicks_link "Link"
|
||||
scope.click_link "Link"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -16,5 +16,5 @@
|
||||
# EOS
|
||||
# @session.should_receive(:https!).with(true)
|
||||
# @session.should_receive(:get).with("/page/sub", {})
|
||||
# @session.clicks_link "Jump to sub page"
|
||||
# @session.click_link "Jump to sub page"
|
||||
# end
|
Loading…
Reference in New Issue
Block a user