Navigation Menu

Skip to content

Commit

Permalink
Rename clicks_link and clicks_link_within to click_link and click_lin…
Browse files Browse the repository at this point in the history
…k_within
  • Loading branch information
brynary committed Nov 5, 2008
1 parent ea193e1 commit 24ac5d3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
12 changes: 6 additions & 6 deletions lib/webrat/core/scope.rb
Expand Up @@ -102,7 +102,7 @@ def clicks_area(area_name)
# 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.
#
Expand All @@ -112,16 +112,16 @@ def clicks_area(area_name)
# 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.
Expand Down
10 changes: 5 additions & 5 deletions lib/webrat/core/session.rb
Expand Up @@ -117,17 +117,17 @@ def 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:
# 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)
Expand Down
9 changes: 6 additions & 3 deletions lib/webrat/selenium/selenium_session.rb
Expand Up @@ -37,17 +37,20 @@ def click_button(button_text_or_regexp = nil, options = {})

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
Expand Down
54 changes: 27 additions & 27 deletions spec/api/click_link_spec.rb
@@ -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
Expand All @@ -10,23 +10,23 @@
<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
@session.response_body = <<-EOS
<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
@session.response_body = <<-EOS
<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


Expand All @@ -35,23 +35,23 @@
<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
@session.response_body = <<-EOS
<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
@session.response_body = <<-EOS
<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
Expand All @@ -70,7 +70,7 @@
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
Expand All @@ -89,7 +89,7 @@
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
Expand All @@ -103,7 +103,7 @@
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
Expand All @@ -117,7 +117,7 @@
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
Expand All @@ -136,7 +136,7 @@
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
Expand All @@ -155,7 +155,7 @@
EOS

lambda {
@session.clicks_link "Link"
@session.click_link "Link"
}.should raise_error
end

Expand All @@ -164,7 +164,7 @@
<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|
Expand All @@ -173,7 +173,7 @@
<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

Expand All @@ -183,7 +183,7 @@
EOS

lambda {
@session.clicks_link "Missing link"
@session.click_link "Missing link"
}.should raise_error
end

Expand All @@ -192,23 +192,23 @@
<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
@session.response_body = <<-EOS
<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
@session.response_body = <<-EOS
<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
Expand All @@ -217,7 +217,7 @@
<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
Expand All @@ -227,7 +227,7 @@
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
Expand All @@ -236,7 +236,7 @@
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
Expand All @@ -248,7 +248,7 @@
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
Expand All @@ -257,7 +257,7 @@
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
Expand All @@ -266,15 +266,15 @@
<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
@session.response_body = <<-EOS
<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
Expand All @@ -283,6 +283,6 @@
<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
2 changes: 1 addition & 1 deletion spec/api/within_spec.rb
Expand Up @@ -15,7 +15,7 @@

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

Expand Down
2 changes: 1 addition & 1 deletion spec/webrat/rails/rails_spec.rb
Expand Up @@ -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

0 comments on commit 24ac5d3

Please sign in to comment.