mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
DSL only has a single app
Just makes more sense
This commit is contained in:
parent
67cddc7008
commit
eef4e74a9f
2 changed files with 9 additions and 11 deletions
|
@ -2,6 +2,8 @@ module Webcat
|
||||||
class << self
|
class << self
|
||||||
attr_writer :default_driver, :current_driver
|
attr_writer :default_driver, :current_driver
|
||||||
|
|
||||||
|
attr_accessor :app
|
||||||
|
|
||||||
def default_driver
|
def default_driver
|
||||||
@default_driver || :rack_test
|
@default_driver || :rack_test
|
||||||
end
|
end
|
||||||
|
@ -15,6 +17,12 @@ module Webcat
|
||||||
@current_driver = nil
|
@current_driver = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_session
|
||||||
|
session_pool["#{current_driver}#{app.object_id}"] ||= Webcat::Session.new(current_driver, app)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def session_pool
|
def session_pool
|
||||||
@session_pool ||= {}
|
@session_pool ||= {}
|
||||||
end
|
end
|
||||||
|
@ -22,12 +30,6 @@ module Webcat
|
||||||
|
|
||||||
extend(self)
|
extend(self)
|
||||||
|
|
||||||
attr_accessor :app
|
|
||||||
|
|
||||||
def current_session
|
|
||||||
driver = Webcat.current_driver
|
|
||||||
Webcat.session_pool["#{driver}#{app.object_id}"] ||= Webcat::Session.new(driver, app)
|
|
||||||
end
|
|
||||||
|
|
||||||
SESSION_METHODS = [
|
SESSION_METHODS = [
|
||||||
:visit, :body, :click_link, :click_button, :fill_in, :choose,
|
:visit, :body, :click_link, :click_button, :fill_in, :choose,
|
||||||
|
@ -36,7 +38,7 @@ module Webcat
|
||||||
SESSION_METHODS.each do |method|
|
SESSION_METHODS.each do |method|
|
||||||
class_eval <<-RUBY, __FILE__, __LINE__+1
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
||||||
def #{method}(*args, &block)
|
def #{method}(*args, &block)
|
||||||
current_session.#{method}(*args, &block)
|
Webcat.current_session.#{method}(*args, &block)
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,13 +100,9 @@ describe Webcat do
|
||||||
include Webcat
|
include Webcat
|
||||||
end
|
end
|
||||||
foo = klass.new
|
foo = klass.new
|
||||||
foo.app = TestApp
|
|
||||||
foo.visit('/with_html')
|
foo.visit('/with_html')
|
||||||
foo.click_link('ullamco')
|
foo.click_link('ullamco')
|
||||||
foo.body.should include('Another World')
|
foo.body.should include('Another World')
|
||||||
foo.app = proc { [200, {}, "Another Application"] }
|
|
||||||
foo.visit('/')
|
|
||||||
foo.body.should include('Another Application')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue