webrat/spec/api/visit_spec.rb
2008-11-28 00:34:35 -05:00

50 lines
1.1 KiB
Ruby

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "visit" do
before do
with_html <<-HTML
<html>
Hello world
</html>
HTML
end
it "should use get" do
webrat_session.should_receive(:get).with("/", {})
visit("/")
end
it "should assert valid response" do
webrat_session.response_code = 501
lambda { visit("/") }.should raise_error(Webrat::PageLoadError)
end
[200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do
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
end
describe "visit with referer" do
before do
webrat_session.instance_variable_set(:@current_url, "/old_url")
with_html <<-HTML
<html>
Hello world
</html>
HTML
end
it "should use get with referer header" do
webrat_session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
visit("/")
end
end