Created
March 16, 2012 09:32
-
-
Save stanislaw/2049280 to your computer and use it in GitHub Desktop.
Cucumber & Capybara against Spork - Always run tests in the same browser.
This file contains 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
require 'rubygems' | |
require 'spork' | |
ENV["RAILS_ENV"] = 'test' | |
Spork.prefork do | |
require 'cucumber/rails' | |
require 'capybara/rails' | |
# ... | |
# This is not even needed because of we starting shared browser in Spork process which pid != the cucumber's one. (according to present #browser implementation). | |
# class Capybara::Selenium::Driver < Capybara::Driver::Base | |
# def quit | |
# nothing - do not close browser | |
# rescue Errno::ECONNREFUSED | |
# Browser must have already gone | |
# end | |
# end | |
module Capybara | |
mattr_accessor :shared_session | |
@@shared_session = nil | |
class << self | |
def current_session | |
session_pool["#{current_driver}:#{session_name}:#{app.object_id}"] ||= (current_driver == :selenium ? Capybara.shared_session : Capybara::Session.new(current_driver, app)) | |
end | |
end | |
end | |
Capybara.shared_session = Capybara::Session.new(:selenium, Capybara.app) | |
# Need to touch browser to get @browser (again, see #browser) | |
Capybara.shared_session.driver.browser | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment