Refactor redirect handling as Merb response doesn't support the redirect? method. All integration specs now passing again.

This commit is contained in:
Josh Knowles 2008-12-29 22:45:55 -05:00
parent b222d3fde3
commit e77495bc04
7 changed files with 108 additions and 90 deletions

View File

@ -110,7 +110,7 @@ For example:
@http_method = http_method @http_method = http_method
@data = data @data = data
request_page(response.location, :get, data) if response.redirect? request_page(response.location, :get, data) if redirect?
return response return response
end end
@ -118,6 +118,10 @@ For example:
def success_code? #:nodoc: def success_code? #:nodoc:
(200..499).include?(response_code) (200..499).include?(response_code)
end end
def redirect? #:nodoc:
response_code / 100 == 3
end
def exception_caught? #:nodoc: def exception_caught? #:nodoc:
response_body =~ /Exception caught/ response_body =~ /Exception caught/

View File

@ -12,7 +12,7 @@ module Webrat #:nodoc:
end end
def response def response
@response ||= TestResponse.new @response ||= Object.new
end end
def response_code def response_code
@ -31,10 +31,4 @@ module Webrat #:nodoc:
def delete(url, data, headers = nil) def delete(url, data, headers = nil)
end end
end end
class TestResponse #:nodoc:
def redirect?
false
end
end
end end

View File

@ -114,7 +114,7 @@ describe Webrat::Session do
end end
it "should follow redirects" do it "should follow redirects" do
webrat_session.response.should_receive(:redirect?).twice.and_return(true, false) webrat_session.should_receive(:redirect?).twice.and_return(true, false)
webrat_session.response.should_receive(:location).once.and_return("/newurl") webrat_session.response.should_receive(:location).once.and_return("/newurl")
webrat_session.request_page("/oldurl", :get, {}) webrat_session.request_page("/oldurl", :get, {})
@ -122,4 +122,20 @@ describe Webrat::Session do
webrat_session.current_url.should == "/newurl" webrat_session.current_url.should == "/newurl"
end end
end end
describe "#redirect?" do
before(:each) do
webrat_session = Webrat::Session.new
end
it "should return true if the last response was a redirect" do
webrat_session.stub!(:response_code => 301)
webrat_session.redirect?.should be_true
end
it "should return false if the last response wasn't a redirect" do
webrat_session.stub!(:response_code => 200)
webrat_session.redirect?.should be_false
end
end
end end

View File

@ -24,7 +24,7 @@ describe "click_area" do
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError) lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError)
end end
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
@ -34,11 +34,12 @@ describe "click_area" do
</map> </map>
</html> </html>
HTML HTML
webrat_session.stub!(:redirect? => false)
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_area "Berlin" }.should_not raise_error lambda { click_area "Berlin" }.should_not raise_error
end end
end end
it "should fail if the area doesn't exist" do it "should fail if the area doesn't exist" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -47,12 +48,12 @@ describe "click_area" do
</map> </map>
</html> </html>
HTML HTML
lambda { lambda {
click_area "Missing area" click_area "Missing area"
}.should raise_error(Webrat::NotFoundError) }.should raise_error(Webrat::NotFoundError)
end end
it "should not be case sensitive" do it "should not be case sensitive" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -64,7 +65,7 @@ describe "click_area" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_area "berlin" click_area "berlin"
end end
it "should follow relative links" do it "should follow relative links" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
@ -78,7 +79,7 @@ describe "click_area" do
webrat_session.should_receive(:get).with("/page/sub", {}) webrat_session.should_receive(:get).with("/page/sub", {})
click_area "Berlin" click_area "Berlin"
end end
it "should follow fully qualified local links" do it "should follow fully qualified local links" do
with_html <<-HTML with_html <<-HTML
<html> <html>

View File

@ -7,10 +7,10 @@ describe "click_button" do
<form method="get" action="/login"></form> <form method="get" action="/login"></form>
</html> </html>
HTML HTML
lambda { click_button }.should raise_error(Webrat::NotFoundError) lambda { click_button }.should raise_error(Webrat::NotFoundError)
end end
it "should fail if input is not a submit button" do it "should fail if input is not a submit button" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -23,7 +23,7 @@ describe "click_button" do
lambda { click_button }.should raise_error(Webrat::NotFoundError) lambda { click_button }.should raise_error(Webrat::NotFoundError)
end end
it "should fail if button is disabled" do it "should fail if button is disabled" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -35,7 +35,7 @@ describe "click_button" do
lambda { click_button }.should raise_error(Webrat::DisabledFieldError) lambda { click_button }.should raise_error(Webrat::DisabledFieldError)
end end
it "should default to get method" do it "should default to get method" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -47,7 +47,7 @@ describe "click_button" do
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button click_button
end end
it "should assert valid response" do it "should assert valid response" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -59,7 +59,7 @@ describe "click_button" do
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_button }.should raise_error(Webrat::PageLoadError) lambda { click_button }.should raise_error(Webrat::PageLoadError)
end end
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
@ -69,11 +69,12 @@ describe "click_button" do
</form> </form>
</html> </html>
HTML HTML
webrat_session.stub!(:redirect? => false)
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_button }.should_not raise_error lambda { click_button }.should_not raise_error
end end
end end
it "should submit the first form by default" do it "should submit the first form by default" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -88,7 +89,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/form1", {}) webrat_session.should_receive(:get).with("/form1", {})
click_button click_button
end end
it "should not explode on file fields" do it "should not explode on file fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -100,7 +101,7 @@ describe "click_button" do
HTML HTML
click_button click_button
end end
it "should submit the form with the specified button" do it "should submit the form with the specified button" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -115,7 +116,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/form2", {}) webrat_session.should_receive(:get).with("/form2", {})
click_button "Form2" click_button "Form2"
end end
it "should use action from form" do it "should use action from form" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -127,7 +128,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
end end
it "should use method from form" do it "should use method from form" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -139,7 +140,7 @@ describe "click_button" do
webrat_session.should_receive(:post) webrat_session.should_receive(:post)
click_button click_button
end end
it "should send button as param if it has a name" do it "should send button as param if it has a name" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -152,7 +153,7 @@ describe "click_button" do
webrat_session.should_receive(:post).with("/login", "login" => "Login") webrat_session.should_receive(:post).with("/login", "login" => "Login")
click_button("Login") click_button("Login")
end end
it "should not send button as param if it has no name" do it "should not send button as param if it has no name" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -177,8 +178,8 @@ describe "click_button" do
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"})
click_button click_button
end end
it "should send default hidden field values" do it "should send default hidden field values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -191,7 +192,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"})
click_button click_button
end end
it "should send default text field values" do it "should send default text field values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -204,7 +205,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"})
click_button click_button
end end
it "should not send disabled field values" do it "should not send disabled field values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -221,7 +222,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
end end
it "should send default checked fields" do it "should send default checked fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -234,7 +235,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
click_button click_button
end end
it "should send default radio options" do it "should send default radio options" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -250,7 +251,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"})
click_button click_button
end end
it "should send correct data for rails style unchecked fields" do it "should send correct data for rails style unchecked fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -264,7 +265,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
click_button click_button
end end
it "should send correct data for rails style checked fields" do it "should send correct data for rails style checked fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -302,7 +303,7 @@ describe "click_button" do
"response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]}) "response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]})
click_button click_button
end end
it "should not send default unchecked fields" do it "should not send default unchecked fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -315,7 +316,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
end end
it "should send default textarea values" do it "should send default textarea values" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -328,7 +329,7 @@ describe "click_button" do
webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"}) webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"})
click_button click_button
end end
it "should properly handle HTML entities in textarea default values" do it "should properly handle HTML entities in textarea default values" do
spec = lambda do spec = lambda do
with_html <<-HTML with_html <<-HTML
@ -342,14 +343,14 @@ describe "click_button" do
webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"}) webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
click_button click_button
end end
if Webrat.on_java? if Webrat.on_java?
spec.call spec.call
else else
pending("needs bug fix", &spec) pending("needs bug fix", &spec)
end end
end end
it "should send default selected option value from select" do it "should send default selected option value from select" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -381,7 +382,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "month" => "February") webrat_session.should_receive(:get).with("/login", "month" => "February")
click_button click_button
end end
it "should send first select option value when no option selected" do it "should send first select option value when no option selected" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -397,7 +398,7 @@ describe "click_button" do
webrat_session.should_receive(:get).with("/login", "month" => "1") webrat_session.should_receive(:get).with("/login", "month" => "1")
click_button click_button
end end
it "should handle nested properties" do it "should handle nested properties" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -449,7 +450,7 @@ describe "click_button" do
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button click_button
end end
it "should find buttons by their IDs" do it "should find buttons by their IDs" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -461,7 +462,7 @@ describe "click_button" do
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button "my_button" click_button "my_button"
end end
it "should find image buttons by their alt text" do it "should find image buttons by their alt text" do
with_html <<-HTML with_html <<-HTML
<html> <html>

View File

@ -10,7 +10,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Save & go back" click_link "Save & go back"
end end
it "should use get by default" do it "should use get by default" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -30,7 +30,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text", :method => :get click_link "Link text", :method => :get
end end
it "should click link on substring" do it "should click link on substring" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -40,7 +40,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "ink tex", :method => :get click_link "ink tex", :method => :get
end end
it "should click delete links" do it "should click delete links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -50,8 +50,8 @@ describe "click_link" do
webrat_session.should_receive(:delete).with("/page", {}) webrat_session.should_receive(:delete).with("/page", {})
click_link "Link text", :method => :delete click_link "Link text", :method => :delete
end end
it "should click post links" do it "should click post links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -61,7 +61,7 @@ describe "click_link" do
webrat_session.should_receive(:post).with("/page", {}) webrat_session.should_receive(:post).with("/page", {})
click_link "Link text", :method => :post click_link "Link text", :method => :post
end end
it "should click put links" do it "should click put links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -71,7 +71,7 @@ describe "click_link" do
webrat_session.should_receive(:put).with("/page", {}) webrat_session.should_receive(:put).with("/page", {})
click_link "Link text", :method => :put click_link "Link text", :method => :put
end end
it "should click links by regexp" do it "should click links by regexp" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -81,8 +81,8 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link /link [a-z]/i click_link /link [a-z]/i
end end
it "should click links by id" do it "should click links by id" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a id="link_text_link" href="/page">Link text</a> <a id="link_text_link" href="/page">Link text</a>
@ -91,8 +91,8 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "link_text_link" click_link "link_text_link"
end end
it "should click links by id regexp" do it "should click links by id regexp" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a id="link_text_link" href="/page">Link text</a> <a id="link_text_link" href="/page">Link text</a>
@ -101,7 +101,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link /_text_/ click_link /_text_/
end end
it "should click rails javascript links with authenticity tokens" do it "should click rails javascript links with authenticity tokens" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -122,7 +122,7 @@ describe "click_link" do
webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
click_link "Posts" click_link "Posts"
end end
it "should click rails javascript delete links" do it "should click rails javascript delete links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -143,7 +143,7 @@ describe "click_link" do
webrat_session.should_receive(:delete).with("/posts/1", {}) webrat_session.should_receive(:delete).with("/posts/1", {})
click_link "Delete" click_link "Delete"
end end
it "should click rails javascript post links" do it "should click rails javascript post links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -159,7 +159,7 @@ describe "click_link" do
webrat_session.should_receive(:post).with("/posts", {}) webrat_session.should_receive(:post).with("/posts", {})
click_link "Posts" 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
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -175,7 +175,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/posts", {}) webrat_session.should_receive(:get).with("/posts", {})
click_link "Posts", :javascript => false click_link "Posts", :javascript => false
end end
it "should click rails javascript put links" do it "should click rails javascript put links" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -196,7 +196,7 @@ describe "click_link" do
webrat_session.should_receive(:put).with("/posts", {}) webrat_session.should_receive(:put).with("/posts", {})
click_link "Put" 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
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -213,12 +213,12 @@ describe "click_link" do
return false;">Link</a> return false;">Link</a>
</html> </html>
HTML HTML
lambda { lambda {
click_link "Link" click_link "Link"
}.should raise_error(Webrat::WebratError) }.should raise_error(Webrat::WebratError)
end end
it "should assert valid response" do it "should assert valid response" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -228,7 +228,7 @@ describe "click_link" do
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_link "Link text" }.should raise_error(Webrat::PageLoadError) lambda { click_link "Link text" }.should raise_error(Webrat::PageLoadError)
end end
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
@ -236,23 +236,24 @@ describe "click_link" do
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html> </html>
HTML HTML
webrat_session.stub!(:redirect? => false)
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_link "Link text" }.should_not raise_error lambda { click_link "Link text" }.should_not raise_error
end end
end end
it "should fail is the link doesn't exist" do it "should fail is the link doesn't exist" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html> </html>
HTML HTML
lambda { lambda {
click_link "Missing link" click_link "Missing link"
}.should raise_error(Webrat::NotFoundError) }.should raise_error(Webrat::NotFoundError)
end end
it "should not be case sensitive" do it "should not be case sensitive" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -262,7 +263,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "LINK TEXT" click_link "LINK TEXT"
end end
it "should match link substrings" do it "should match link substrings" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -272,7 +273,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text" click_link "Link text"
end end
it "should work with elements in the link" do it "should work with elements in the link" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -282,7 +283,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text" click_link "Link text"
end end
it "should match the first matching link" do it "should match the first matching link" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -293,7 +294,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page1", {}) webrat_session.should_receive(:get).with("/page1", {})
click_link "Link text" click_link "Link text"
end end
it "should choose the shortest link text match" do it "should choose the shortest link text match" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -301,22 +302,22 @@ describe "click_link" do
<a href="/page2">Link</a> <a href="/page2">Link</a>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page2", {}) webrat_session.should_receive(:get).with("/page2", {})
click_link "Link" click_link "Link"
end end
it "should treat non-breaking spaces as spaces" do it "should treat non-breaking spaces as spaces" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a> <a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page1", {}) webrat_session.should_receive(:get).with("/page1", {})
click_link "This is a link" click_link "This is a link"
end end
it "should not match on non-text contents" do it "should not match on non-text contents" do
pending "needs fix" do pending "needs fix" do
with_html <<-HTML with_html <<-HTML
@ -325,12 +326,12 @@ describe "click_link" do
<a href="/page2">Location</a> <a href="/page2">Location</a>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page2", {}) webrat_session.should_receive(:get).with("/page2", {})
click_link "Location" click_link "Location"
end end
end end
it "should click link within a selector" do it "should click link within a selector" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -340,7 +341,7 @@ describe "click_link" do
</div> </div>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page2", {}) webrat_session.should_receive(:get).with("/page2", {})
click_link_within "#container", "Link" click_link_within "#container", "Link"
end end
@ -366,7 +367,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page/sub", {}) webrat_session.should_receive(:get).with("/page/sub", {})
click_link "Jump to sub page" click_link "Jump to sub page"
end end
it "should follow fully qualified local links" do it "should follow fully qualified local links" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
with_html <<-HTML with_html <<-HTML
@ -377,7 +378,7 @@ describe "click_link" do
webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {}) webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {})
click_link "Jump to sub page" click_link "Jump to sub page"
end end
it "should follow fully qualified local links to example.com" do it "should follow fully qualified local links to example.com" do
with_html <<-HTML with_html <<-HTML
<html> <html>
@ -398,28 +399,28 @@ describe "click_link" do
webrat_session.should_receive(:get).with("/page?foo=bar", {}) webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_link "Jump to foo bar" click_link "Jump to foo bar"
end end
it "should matches_text? on regexp" do it "should matches_text? on regexp" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
link.should_receive(:text).and_return(@link_text_with_nbsp) link.should_receive(:text).and_return(@link_text_with_nbsp)
link.matches_text?(/link/i).should == 0 link.matches_text?(/link/i).should == 0
end end
it "should matches_text? on link_text" do it "should matches_text? on link_text" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
link.should_receive(:text).and_return(@link_text_with_nbsp) link.should_receive(:text).and_return(@link_text_with_nbsp)
link.matches_text?("Link Text").should == 0 link.matches_text?("Link Text").should == 0
end end
it "should matches_text? on substring" do it "should matches_text? on substring" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
link.should_receive(:text).and_return(@link_text_with_nbsp) link.should_receive(:text).and_return(@link_text_with_nbsp)
link.matches_text?("nk Te").should_not be_nil link.matches_text?("nk Te").should_not be_nil
end end
it "should not matches_text? on link_text case insensitive" do it "should not matches_text? on link_text case insensitive" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
@ -428,15 +429,15 @@ describe "click_link" do
link.should_receive(:title).and_return(nil) link.should_receive(:title).and_return(nil)
link.matches_text?("link_text").should == false link.matches_text?("link_text").should == false
end end
it "should match text not include &nbsp;" do it "should match text not include &nbsp;" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
link.should_receive(:text).and_return('LinkText') link.should_receive(:text).and_return('LinkText')
link.matches_text?("LinkText").should == 0 link.matches_text?("LinkText").should == 0
end end
it "should not matches_text? on wrong text" do it "should not matches_text? on wrong text" do
pending "need to update these" pending "need to update these"
link = Webrat::Link.new(webrat_session, nil) link = Webrat::Link.new(webrat_session, nil)
nbsp = [0xA0].pack("U") nbsp = [0xA0].pack("U")
@ -464,5 +465,5 @@ describe "click_link" do
link.should_receive(:inner_html).and_return('<img src="logo.png" />') link.should_receive(:inner_html).and_return('<img src="logo.png" />')
link.matches_text?('logo.png').should == 10 link.matches_text?('logo.png').should == 10
end end
end end

View File

@ -21,6 +21,7 @@ describe "visit" do
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
webrat_session.stub!(:redirect? => false)
webrat_session.response_code = status webrat_session.response_code = status
lambda { visit("/") }.should_not raise_error lambda { visit("/") }.should_not raise_error
end end
@ -31,7 +32,7 @@ describe "visit" do
end end
it "should follow redirects" do it "should follow redirects" do
webrat_session.response.should_receive(:redirect?).twice.and_return(true, false) webrat_session.should_receive(:redirect?).twice.and_return(true, false)
webrat_session.response.should_receive(:location).once.and_return("/newurl") webrat_session.response.should_receive(:location).once.and_return("/newurl")
visit("/oldurl") visit("/oldurl")