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
|
|
|
|
@session = Webrat::TestSession.new
|
2008-05-12 04:23:37 +00:00
|
|
|
@session.response_body = "Hello world"
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use get" do
|
2008-07-25 23:11:56 +00:00
|
|
|
@session.should_receive(:get).with("/", {})
|
2008-11-05 23:20:27 +00:00
|
|
|
@session.visit("/")
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should assert valid response" do
|
2008-10-25 16:30:30 +00:00
|
|
|
@session.response_code = 501
|
2008-11-05 23:20:27 +00:00
|
|
|
lambda { @session.visit("/") }.should raise_error
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
|
|
|
|
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-10-25 16:30:30 +00:00
|
|
|
@session.response_code = status
|
2008-11-05 23:20:27 +00:00
|
|
|
lambda { @session.visit("/") }.should_not raise_error
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-12 03:58:20 +00:00
|
|
|
it "should require a visit before manipulating page" do
|
2008-11-05 23:15:12 +00:00
|
|
|
lambda { @session.fill_in "foo", :with => "blah" }.should raise_error
|
2008-05-12 03:58:20 +00:00
|
|
|
end
|
|
|
|
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
|
|
|
|
@session = Webrat::TestSession.new
|
|
|
|
@session.instance_variable_set(:@current_url, "/old_url")
|
|
|
|
@session.response_body = "Hello world"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should use get with referer header" do
|
|
|
|
@session.should_receive(:get).with("/", {}, {"HTTP_REFERER" => "/old_url"})
|
2008-11-05 23:20:27 +00:00
|
|
|
@session.visit("/")
|
2008-08-20 08:35:57 +00:00
|
|
|
end
|
|
|
|
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|