mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
visit now allow fully qualified URLs.
This also introduces Capybara.run_server, which controls whether Capybara will spool up a server or not.
This commit is contained in:
parent
aec11e22b1
commit
ecdc2bd8c5
6 changed files with 30 additions and 36 deletions
|
|
@ -16,7 +16,7 @@ Install as a gem:
|
|||
|
||||
sudo gem install capybara
|
||||
|
||||
On OSX you may have to install libffi, you can install it via MacPorts via:
|
||||
On OSX you may have to install libffi, you can install it via MacPorts with:
|
||||
|
||||
sudo port install libffi
|
||||
|
||||
|
|
|
|||
|
|
@ -12,17 +12,8 @@ module Capybara
|
|||
class InfiniteRedirectError < TimeoutError; end
|
||||
|
||||
class << self
|
||||
attr_accessor :debug, :asset_root, :app_host
|
||||
attr_writer :default_selector, :default_wait_time
|
||||
|
||||
|
||||
def default_selector
|
||||
@default_selector ||= :xpath
|
||||
end
|
||||
|
||||
def default_wait_time
|
||||
@default_wait_time ||= 2
|
||||
end
|
||||
attr_accessor :debug, :asset_root, :app_host, :run_server
|
||||
attr_accessor :default_selector, :default_wait_time
|
||||
|
||||
def log(message)
|
||||
puts "[capybara] #{message}" if debug
|
||||
|
|
@ -44,3 +35,7 @@ module Capybara
|
|||
autoload :Selenium, 'capybara/driver/selenium_driver'
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.run_server = true
|
||||
Capybara.default_selector = :xpath
|
||||
Capybara.default_wait_time = 2
|
||||
|
|
|
|||
|
|
@ -51,9 +51,8 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
unless Capybara.app_host
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
end
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot if Capybara.run_server
|
||||
end
|
||||
|
||||
def visit(path)
|
||||
|
|
@ -98,11 +97,7 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
|||
private
|
||||
|
||||
def url(path)
|
||||
if rack_server
|
||||
rack_server.url(path)
|
||||
else
|
||||
Capybara.app_host.to_s + path
|
||||
end
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -69,9 +69,8 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
unless Capybara.app_host
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
end
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot if Capybara.run_server
|
||||
end
|
||||
|
||||
def visit(path)
|
||||
|
|
@ -107,11 +106,7 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
|||
private
|
||||
|
||||
def url(path)
|
||||
if rack_server
|
||||
rack_server.url(path)
|
||||
else
|
||||
Capybara.app_host.to_s + path
|
||||
end
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,26 +26,26 @@ class Capybara::Server
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
find_available_port
|
||||
boot
|
||||
end
|
||||
|
||||
def host
|
||||
'localhost'
|
||||
"localhost"
|
||||
end
|
||||
|
||||
def url(path)
|
||||
path = URI.parse(path).request_uri if path =~ /^http/
|
||||
"http://#{host}:#{port}#{path}"
|
||||
if path =~ /^http/
|
||||
path
|
||||
else
|
||||
(Capybara.app_host || "http://#{host}:#{port}") + path.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def responsive?
|
||||
is_running_on_port?(port)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def boot
|
||||
find_available_port
|
||||
Capybara.log "application has already booted" and return if responsive?
|
||||
Capybara.log "booting Rack applicartion on port #{port}"
|
||||
|
||||
|
|
@ -69,6 +69,8 @@ private
|
|||
exit
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_available_port
|
||||
@port = 9887
|
||||
@port += 1 while is_port_open?(@port) and not is_running_on_port?(@port)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,20 @@ describe Capybara::Driver::Culerity do
|
|||
|
||||
before(:all) do
|
||||
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
||||
Capybara.run_server = false
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
Capybara.app_host = nil
|
||||
Capybara.run_server = true
|
||||
end
|
||||
|
||||
it "should navigate to a fully qualified remote page" do
|
||||
@driver.visit('http://elabs.se/contact')
|
||||
@driver.body.should include('Edithouse eLabs AB')
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with header support"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue