1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Make DSL include:able

This commit is contained in:
Jonas Nicklas 2009-11-12 18:09:29 +01:00
parent 0abcd61101
commit 95a92300d8
2 changed files with 38 additions and 21 deletions

View file

@ -1,26 +1,34 @@
module Webcat
class << self
attr_writer :default_driver, :current_driver
def default_driver
@default_driver || :rack_test
end
def current_driver
@current_driver || default_driver
end
alias_method :mode, :current_driver
def use_default_driver
@current_driver = nil
end
def session_pool
@session_pool ||= {}
end
end
extend(self)
attr_writer :default_driver, :current_driver
attr_accessor :app
def default_driver
@default_driver || :rack_test
end
def current_driver
@current_driver || default_driver
end
alias_method :mode, :current_driver
def use_default_driver
@current_driver = nil
end
def current_session
session_pool["#{current_driver}#{app.object_id}"] ||= Webcat::Session.new(current_driver, app)
driver = Webcat.current_driver
Webcat.session_pool["#{driver}#{app.object_id}"] ||= Webcat::Session.new(driver, app)
end
SESSION_METHODS = [
:visit, :body, :click_link, :click_button, :fill_in, :choose,
:set_hidden_field, :check, :uncheck, :attach_file, :select
@ -33,9 +41,4 @@ module Webcat
RUBY
end
private
def session_pool
@session_pool ||= {}
end
end

View file

@ -94,6 +94,20 @@ describe Webcat do
end
it_should_behave_like "session"
it "should be possible to include it in another class" do
klass = Class.new do
include Webcat
end
foo = klass.new
foo.app = TestApp
foo.visit('/with_html')
foo.click_link('ullamco')
foo.body.should include('Another World')
foo.app = proc { [200, {}, "Another Application"] }
foo.visit('/')
foo.body.should include('Another Application')
end
end
end