Permalink
Browse files

Fix visiting relative URLs when no server started, closes #861

  • Loading branch information...
1 parent d21d6dd commit 7da8833df2a1817362d9998ad652e7417c337383 @jnicklas jnicklas committed Nov 14, 2012
Showing with 24 additions and 5 deletions.
  1. +5 −3 lib/capybara/session.rb
  2. +15 −0 lib/capybara/spec/session/visit_spec.rb
  3. +2 −1 spec/dsl_spec.rb
  4. +2 −1 spec/rack_test_spec.rb
View
@@ -170,10 +170,12 @@ def current_url
def visit(url)
@touched = true
+ if url !~ /^http/ and Capybara.app_host
+ url = Capybara.app_host + url.to_s
+ end
+
if @server
- unless url =~ /^http/
- url = (Capybara.app_host || "http://#{@server.host}:#{@server.port}") + url.to_s
- end
+ url = "http://#{@server.host}:#{@server.port}" + url.to_s unless url =~ /^http/
if Capybara.always_include_port
uri = URI.parse(url)
@@ -43,6 +43,21 @@
end
end
+ context "without a server", :requires => [:server] do
+ it "should respect `app_host`" do
+ serverless_session = Capybara::Session.new(@session.mode, nil)
+ Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
+ serverless_session.visit("/foo")
+ serverless_session.should have_content("Another World")
+ end
+
+ it "should visit a fully qualified URL" do
+ serverless_session = Capybara::Session.new(@session.mode, nil)
+ serverless_session.visit("http://#{@session.server.host}:#{@session.server.port}/foo")
+ serverless_session.should have_content("Another World")
+ end
+ end
+
it "should send no referer when visiting a page" do
@session.visit '/get_referer'
@session.should have_content 'No referer'
View
@@ -9,7 +9,8 @@ class TestClass
:js,
:screenshot,
:frames,
- :windows
+ :windows,
+ :server
]
describe Capybara::DSL do
View
@@ -8,7 +8,8 @@ module TestSessions
:js,
:screenshot,
:frames,
- :windows
+ :windows,
+ :server
]
describe Capybara::Session do

0 comments on commit 7da8833

Please sign in to comment.