Created
July 21, 2011 05:08
-
-
Save jonsgreen/1096534 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOMAIN = "smackaho.st" | |
Given /^I am in subdomain "(.+)"$/ do |subdomain| | |
if Capybara.current_driver == :webkit | |
port = page.driver.instance_variable_get(:@rack_server).port | |
Capybara.app_host = "http://#{subdomain}.#{DOMAIN}:#{port}" | |
else | |
Capybara.default_host = "http://#{subdomain}.#{DOMAIN}" | |
switch_session(subdomain) | |
visit("http://#{subdomain}.#{DOMAIN}") | |
end | |
end | |
module Capybara | |
module Driver | |
module Sessions | |
def set_session(id) | |
Capybara.instance_variable_set('@session_pool', { | |
"#{Capybara.current_driver}#{Capybara.app.object_id}" => $sessions[id] | |
}) | |
end | |
def switch_session(id) | |
$sessions ||= {} | |
$sessions[:default] ||= Capybara.current_session | |
$sessions[id] ||= Capybara::Session.new(Capybara.current_driver, Capybara.app) | |
set_session(id) | |
end | |
def in_session(id, &block) | |
switch_session(id) | |
yield | |
set_session(:default) | |
end | |
end | |
end | |
end | |
World(Capybara::Driver::Sessions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment