Rename clicks_link and clicks_link_within to click_link and click_link_within

This commit is contained in:
Bryan Helmkamp 2008-11-05 18:27:55 -05:00
parent ea193e15d2
commit 24ac5d3fb7
6 changed files with 46 additions and 43 deletions

View File

@ -102,7 +102,7 @@ module Webrat
# Issues a request for the URL pointed to by a link on the current page, # 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. # 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 # JavaScript onclick handlers for PUT, POST and DELETE links, as well as
# CSRF authenticity tokens if they are present. # CSRF authenticity tokens if they are present.
# #
@ -112,16 +112,16 @@ module Webrat
# for making the link request # for making the link request
# #
# Example: # 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 # click_link "Sign up", :method => :put
def clicks_link(link_text, options = {}) def click_link(link_text, options = {})
find_link(link_text).click(options) find_link(link_text).click(options)
end 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 # Verifies that a submit button exists for the form, then submits the form, follows
# any redirects, and verifies the final page was successful. # any redirects, and verifies the final page was successful.

View File

@ -117,17 +117,17 @@ module Webrat
alias_method :reload, :reloads 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: # Example:
# clicks_link_within "#user_12", "Vote" # click_link_within "#user_12", "Vote"
def clicks_link_within(selector, link_text) def click_link_within(selector, link_text)
within(selector) do |scope| within(selector) do |scope|
scope.clicks_link(link_text) scope.click_link(link_text)
end end
end end
alias_method :click_link_within, :clicks_link_within alias_method :clicks_link_within, :click_link_within
def within(selector) def within(selector)
yield Scope.new(self, response_body, selector) yield Scope.new(self, response_body, selector)

View File

@ -37,18 +37,21 @@ module Webrat
alias_method :clicks_button, :click_button 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) pattern = adjust_if_regexp(link_text_or_regexp)
@selenium.click("webratlink=#{pattern}") @selenium.click("webratlink=#{pattern}")
wait_for_result(options[:wait]) wait_for_result(options[:wait])
end 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}") @selenium.click("webratlinkwithin=#{selector}|#{link_text}")
wait_for_result(options[:wait]) wait_for_result(options[:wait])
end end
alias_method :clicks_link_within, :click_link_within
def wait_for_result(wait_type) def wait_for_result(wait_type)
if wait_type == :ajax if wait_type == :ajax
wait_for_ajax wait_for_ajax

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "clicks_link" do describe "click_link" do
before do before do
@session = Webrat::TestSession.new @session = Webrat::TestSession.new
end end
@ -10,7 +10,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link "Link text" @session.click_link "Link text"
end end
it "should click get links" do it "should click get links" do
@ -18,7 +18,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link "Link text", :method => :get @session.click_link "Link text", :method => :get
end end
it "should click delete links" do it "should click delete links" do
@ -26,7 +26,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:delete).with("/page", {}) @session.should_receive(:delete).with("/page", {})
@session.clicks_link "Link text", :method => :delete @session.click_link "Link text", :method => :delete
end end
@ -35,7 +35,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:post).with("/page", {}) @session.should_receive(:post).with("/page", {})
@session.clicks_link "Link text", :method => :post @session.click_link "Link text", :method => :post
end end
it "should click put links" do it "should click put links" do
@ -43,7 +43,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:put).with("/page", {}) @session.should_receive(:put).with("/page", {})
@session.clicks_link "Link text", :method => :put @session.click_link "Link text", :method => :put
end end
it "should click links by regexp" do it "should click links by regexp" do
@ -51,7 +51,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link /link [a-z]/i @session.click_link /link [a-z]/i
end end
it "should click rails javascript links with authenticity tokens" do it "should click rails javascript links with authenticity tokens" do
@ -70,7 +70,7 @@ describe "clicks_link" do
return false;">Posts</a> return false;">Posts</a>
EOS EOS
@session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") @session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
@session.clicks_link "Posts" @session.click_link "Posts"
end end
it "should click rails javascript delete links" do it "should click rails javascript delete links" do
@ -89,7 +89,7 @@ describe "clicks_link" do
return false;">Delete</a> return false;">Delete</a>
EOS EOS
@session.should_receive(:delete).with("/posts/1", {}) @session.should_receive(:delete).with("/posts/1", {})
@session.clicks_link "Delete" @session.click_link "Delete"
end end
it "should click rails javascript post links" do it "should click rails javascript post links" do
@ -103,7 +103,7 @@ describe "clicks_link" do
return false;">Posts</a> return false;">Posts</a>
EOS EOS
@session.should_receive(:post).with("/posts", {}) @session.should_receive(:post).with("/posts", {})
@session.clicks_link "Posts" @session.click_link "Posts"
end end
it "should click rails javascript post links without javascript" do it "should click rails javascript post links without javascript" do
@ -117,7 +117,7 @@ describe "clicks_link" do
return false;">Posts</a> return false;">Posts</a>
EOS EOS
@session.should_receive(:get).with("/posts", {}) @session.should_receive(:get).with("/posts", {})
@session.clicks_link "Posts", :javascript => false @session.click_link "Posts", :javascript => false
end end
it "should click rails javascript put links" do it "should click rails javascript put links" do
@ -136,7 +136,7 @@ describe "clicks_link" do
return false;">Put</a></h2> return false;">Put</a></h2>
EOS EOS
@session.should_receive(:put).with("/posts", {}) @session.should_receive(:put).with("/posts", {})
@session.clicks_link "Put" @session.click_link "Put"
end end
it "should fail if the javascript link doesn't have a value for the _method input" do 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 EOS
lambda { lambda {
@session.clicks_link "Link" @session.click_link "Link"
}.should raise_error }.should raise_error
end end
@ -164,7 +164,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.response_code = 501 @session.response_code = 501
lambda { @session.clicks_link "Link text" }.should raise_error lambda { @session.click_link "Link text" }.should raise_error
end end
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
@ -173,7 +173,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.response_code = status @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
end end
@ -183,7 +183,7 @@ describe "clicks_link" do
EOS EOS
lambda { lambda {
@session.clicks_link "Missing link" @session.click_link "Missing link"
}.should raise_error }.should raise_error
end end
@ -192,7 +192,7 @@ describe "clicks_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link "LINK TEXT" @session.click_link "LINK TEXT"
end end
it "should match link substrings" do 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> <a href="/page">This is some cool link text, isn't it?</a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link "Link text" @session.click_link "Link text"
end end
it "should work with elements in the link" do 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> <a href="/page"><span>Link text</span></a>
EOS EOS
@session.should_receive(:get).with("/page", {}) @session.should_receive(:get).with("/page", {})
@session.clicks_link "Link text" @session.click_link "Link text"
end end
it "should match the first matching link" do it "should match the first matching link" do
@ -217,7 +217,7 @@ describe "clicks_link" do
<a href="/page2">Link text</a> <a href="/page2">Link text</a>
EOS EOS
@session.should_receive(:get).with("/page1", {}) @session.should_receive(:get).with("/page1", {})
@session.clicks_link "Link text" @session.click_link "Link text"
end end
it "should choose the shortest link text match" do it "should choose the shortest link text match" do
@ -227,7 +227,7 @@ describe "clicks_link" do
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@session.clicks_link "Link" @session.click_link "Link"
end end
it "should treat non-breaking spaces as spaces" do it "should treat non-breaking spaces as spaces" do
@ -236,7 +236,7 @@ describe "clicks_link" do
EOS EOS
@session.should_receive(:get).with("/page1", {}) @session.should_receive(:get).with("/page1", {})
@session.clicks_link "This is a link" @session.click_link "This is a link"
end end
it "should click link within a selector" do it "should click link within a selector" do
@ -248,7 +248,7 @@ describe "clicks_link" do
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@session.clicks_link_within "#container", "Link" @session.click_link_within "#container", "Link"
end end
it "should not make request when link is local anchor" do it "should not make request when link is local anchor" do
@ -257,7 +257,7 @@ describe "clicks_link" do
EOS EOS
# Don't know why @session.should_receive(:get).never doesn't work here # 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.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 end
it "should follow relative links" do it "should follow relative links" do
@ -266,7 +266,7 @@ describe "clicks_link" do
<a href="sub">Jump to sub page</a> <a href="sub">Jump to sub page</a>
EOS EOS
@session.should_receive(:get).with("/page/sub", {}) @session.should_receive(:get).with("/page/sub", {})
@session.clicks_link "Jump to sub page" @session.click_link "Jump to sub page"
end end
it "should follow fully qualified local links" do 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> <a href="http://www.example.com/page/sub">Jump to sub page</a>
EOS EOS
@session.should_receive(:get).with("http://www.example.com/page/sub", {}) @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 end
it "should follow query parameters" do it "should follow query parameters" do
@ -283,6 +283,6 @@ describe "clicks_link" do
<a href="?foo=bar">Jump to foo bar</a> <a href="?foo=bar">Jump to foo bar</a>
EOS EOS
@session.should_receive(:get).with("/page?foo=bar", {}) @session.should_receive(:get).with("/page?foo=bar", {})
@session.clicks_link "Jump to foo bar" @session.click_link "Jump to foo bar"
end end
end end

View File

@ -15,7 +15,7 @@ describe "within" do
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@session.within "#container" do |scope| @session.within "#container" do |scope|
scope.clicks_link "Link" scope.click_link "Link"
end end
end end

View File

@ -16,5 +16,5 @@
# EOS # EOS
# @session.should_receive(:https!).with(true) # @session.should_receive(:https!).with(true)
# @session.should_receive(:get).with("/page/sub", {}) # @session.should_receive(:get).with("/page/sub", {})
# @session.clicks_link "Jump to sub page" # @session.click_link "Jump to sub page"
# end # end