From 95a92300d83c5abb43f198140ad684e3169bc139 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Thu, 12 Nov 2009 18:09:29 +0100 Subject: [PATCH] Make DSL include:able --- lib/webcat/dsl.rb | 45 ++++++++++++++++++++++++--------------------- spec/dsl_spec.rb | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/webcat/dsl.rb b/lib/webcat/dsl.rb index b9cb7ea0..94e6a681 100644 --- a/lib/webcat/dsl.rb +++ b/lib/webcat/dsl.rb @@ -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 diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index 12123fb0..4e54768a 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -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