webrat/spec/public/visit_spec.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2008-11-05 23:20:27 +00:00
describe "visit" do
before do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<html>
2008-11-23 05:22:49 +00:00
Hello world
</html>
2008-11-23 05:22:49 +00:00
HTML
end
it "should use get" do
webrat_session.should_receive(:get).with("/", {})
2008-11-23 05:22:49 +00:00
visit("/")
end
it "should assert valid response" do
2008-11-23 05:22:49 +00:00
webrat_session.response_code = 501
lambda { visit("/") }.should raise_error(Webrat::PageLoadError)
end
[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
webrat_session.stub!(:redirect? => false)
2008-11-23 05:22:49 +00:00
webrat_session.response_code = status
lambda { visit("/") }.should_not raise_error
end
end
it "should require a visit before manipulating page" do
lambda { fill_in "foo", :with => "blah" }.should raise_error(Webrat::WebratError)
end
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")
current_url.should == "/oldurl"
2009-01-05 04:56:52 +00:00
end
end
2008-11-05 23:20:27 +00:00
describe "visit with referer" do
before do
2008-11-23 05:22:49 +00:00
webrat_session.instance_variable_set(:@current_url, "/old_url")
with_html <<-HTML
<html>
2008-11-23 05:22:49 +00:00
Hello world
</html>
2008-11-23 05:22:49 +00:00
HTML
end
it "should use get with referer header" do
webrat_session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
2008-11-23 05:22:49 +00:00
visit("/")
end
end