2008-05-12 03:58:20 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
2008-11-05 23:20:27 +00:00
|
|
|
describe "visit" do
|
2008-05-12 03:58:20 +00:00
|
|
|
before do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-23 05:22:49 +00:00
|
|
|
Hello world
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use get" do
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
visit("/")
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
2008-12-30 02:19:13 +00:00
|
|
|
|
2008-05-12 03:58:20 +00:00
|
|
|
it "should assert valid response" do
|
2008-11-23 05:22:49 +00:00
|
|
|
webrat_session.response_code = 501
|
2008-11-23 19:08:34 +00:00
|
|
|
lambda { visit("/") }.should raise_error(Webrat::PageLoadError)
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
2008-12-30 02:19:13 +00:00
|
|
|
|
2008-10-25 16:30:30 +00:00
|
|
|
[200, 300, 400, 499].each do |status|
|
2008-10-25 21:17:00 +00:00
|
|
|
it "should consider the #{status} status code as success" do
|
2008-12-30 03:45:55 +00:00
|
|
|
webrat_session.stub!(:redirect? => false)
|
2008-11-23 05:22:49 +00:00
|
|
|
webrat_session.response_code = status
|
|
|
|
lambda { visit("/") }.should_not raise_error
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|
|
|
|
end
|
2008-12-30 02:19:13 +00:00
|
|
|
|
2008-05-12 03:58:20 +00:00
|
|
|
it "should require a visit before manipulating page" do
|
2008-11-23 19:08:34 +00:00
|
|
|
lambda { fill_in "foo", :with => "blah" }.should raise_error(Webrat::WebratError)
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
2008-12-30 02:19:13 +00:00
|
|
|
|
2009-01-05 04:56:52 +00:00
|
|
|
it "should not follow external redirects" do
|
|
|
|
webrat_session.should_receive(:internal_redirect?).and_return(false)
|
|
|
|
|
|
|
|
visit("/oldurl")
|
|
|
|
|
2009-05-11 20:48:28 +00:00
|
|
|
current_url.should == "/oldurl"
|
2009-01-05 04:56:52 +00:00
|
|
|
end
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
2008-08-20 08:35:57 +00:00
|
|
|
|
2008-11-05 23:20:27 +00:00
|
|
|
describe "visit with referer" do
|
2008-08-20 08:35:57 +00:00
|
|
|
before do
|
2008-11-23 05:22:49 +00:00
|
|
|
webrat_session.instance_variable_set(:@current_url, "/old_url")
|
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-23 05:22:49 +00:00
|
|
|
Hello world
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2008-08-20 08:35:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use get with referer header" do
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
|
2008-11-23 05:22:49 +00:00
|
|
|
visit("/")
|
2008-08-20 08:35:57 +00:00
|
|
|
end
|
2008-12-30 02:19:13 +00:00
|
|
|
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|