2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#visit' do
|
|
|
|
it "should fetch a response from the driver with a relative url" do
|
|
|
|
@session.visit('/')
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Hello world!')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit('/foo')
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Another World')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fetch a response from the driver with an absolute url with a port" do
|
|
|
|
# Preparation
|
|
|
|
@session.visit('/')
|
|
|
|
root_uri = URI.parse(@session.current_url)
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}:#{root_uri.port}/")
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Hello world!')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}:#{root_uri.port}/foo")
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Another World')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "when Capybara.always_include_port is true" do
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
let(:root_uri) do
|
|
|
|
@session.visit('/')
|
|
|
|
URI.parse(@session.current_url)
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
before(:each) do
|
|
|
|
Capybara.always_include_port = true
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
after(:each) do
|
|
|
|
Capybara.always_include_port = false
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should fetch a response from the driver with an absolute url without a port" do
|
|
|
|
@session.visit("http://#{root_uri.host}/")
|
|
|
|
URI.parse(@session.current_url).port.should == root_uri.port
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Hello world!')
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit("http://#{root_uri.host}/foo")
|
|
|
|
URI.parse(@session.current_url).port.should == root_uri.port
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content('Another World')
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send no referer when visiting a page" do
|
|
|
|
@session.visit '/get_referer'
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content 'No referer'
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send no referer when visiting a second page" do
|
|
|
|
@session.visit '/get_referer'
|
|
|
|
@session.visit '/get_referer'
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content 'No referer'
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send a referer when following a link" do
|
|
|
|
@session.visit '/referer_base'
|
|
|
|
@session.find('//a[@href="/get_referer"]').click
|
|
|
|
@session.body.should match %r{http://.*/referer_base}
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should preserve the original referer URL when following a redirect" do
|
|
|
|
@session.visit('/referer_base')
|
|
|
|
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
|
|
|
@session.body.should match %r{http://.*/referer_base}
|
|
|
|
end
|
2012-07-13 06:59:57 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should send a referer when submitting a form" do
|
|
|
|
@session.visit '/referer_base'
|
|
|
|
@session.find('//input').click
|
|
|
|
@session.body.should match %r{http://.*/referer_base}
|
2012-07-13 06:59:57 -04:00
|
|
|
end
|
|
|
|
end
|