lib/polonium/configuration.rb in polonium-0.1.1 vs lib/polonium/configuration.rb in polonium-0.2.0

- old
+ new

@@ -7,45 +7,51 @@ Suite = "suite" unless const_defined? :Suite Test = "test" unless const_defined? :Test end FIREFOX = "firefox" unless const_defined? :FIREFOX IEXPLORE = "iexplore" unless const_defined? :IEXPLORE + SERVER_RUNNERS = { + :webrick => ServerRunners::WebrickServerRunner, + :mongrel => ServerRunners::MongrelServerRunner, + :external => ServerRunners::ExternalServerRunner + } unless const_defined? :SERVER_RUNNERS class << self # The instance of the Singleton Configuration. On its initial call, the initial configuration is set. # The initial configuration is based on Environment variables and defaults. # The environment variables are: # * RAILS_ENV - The Rails environment (defaults: test) # * selenium_server_host - The host name for the Selenium RC server (default: localhost) # * selenium_server_port - The port for the Selenium RC server (default: 4444) - # * webrick_host - The host name that the application server will start under (default: localhost) - # * webrick_port - The port that the application server will start under (default: 4000) + # * external_app_server_host - The host name that the Rails application server will start under (default: localhost) + # * external_app_server_port - The port that the Rails application server will start under (default: 4000) # * app_server_engine - The type of server the application will be run with (webrick or mongrel) # * internal_app_server_host - The host name for the Application server that the Browser will access (default: localhost) # * internal_app_server_host - The port for the Application server that the Browser will access (default: 4000) # * keep_browser_open_on_failure - If there is a failure in the test suite, keep the browser window open (default: false) # * verify_remote_app_server_is_running - Raise an exception if the Application Server is not running (default: true) def instance - return @instance if @instance - @instance = new - @instance.env = ENV + @instance ||= begin + @instance = new + @instance.env = ENV - @instance.browser = FIREFOX - @instance.selenium_server_host = "localhost" # address of selenium RC server (java) - @instance.selenium_server_port = 4444 - @instance.app_server_engine = :webrick - @instance.internal_app_server_host = "0.0.0.0" # internal address of app server (webrick or mongrel) - @instance.internal_app_server_port = 4000 - @instance.external_app_server_host = "localhost" # external address of app server (webrick or mongrel) - @instance.external_app_server_port = 4000 - @instance.server_engine = :webrick - @instance.keep_browser_open_on_failure = false - @instance.browser_mode = BrowserMode::Suite - @instance.verify_remote_app_server_is_running = true + @instance.browser = FIREFOX + @instance.selenium_server_host = "localhost" # address of selenium RC server (java) + @instance.selenium_server_port = 4444 + @instance.app_server_engine = :webrick + @instance.internal_app_server_host = "0.0.0.0" # internal address of app server (webrick or mongrel) + @instance.internal_app_server_port = 4000 + @instance.external_app_server_host = "localhost" # external address of app server (webrick or mongrel) + @instance.external_app_server_port = 4000 + @instance.server_engine = :webrick + @instance.keep_browser_open_on_failure = false + @instance.browser_mode = BrowserMode::Suite + @instance.verify_remote_app_server_is_running = true - establish_environment - @instance + establish_environment + @instance + end end attr_writer :instance private def establish_environment @@ -79,11 +85,10 @@ instance.env end end attr_accessor( - :configuration, :env, :rails_env, :rails_root, :browser, :driver, @@ -103,11 +108,10 @@ def initialize self.verify_remote_app_server_is_running = true @after_driver_started_listeners = [] @app_server_initialization = proc {} - @failure_has_occurred = false end # A callback hook that gets run after the Selenese Interpreter is started. def after_driver_started(&block) @after_driver_started_listeners << block @@ -123,15 +127,10 @@ # The browser formatted for the Selenese driver. def formatted_browser return "*#{@browser}" end - # Has a failure occurred in the tests? - def failure_has_occurred? - @failure_has_occurred = true - end - # The http host name and port to be entered into the browser address bar def browser_url "http://#{external_app_server_host}:#{external_app_server_port}" end @@ -165,11 +164,10 @@ return nil unless suite_browser_mode? @driver ||= create_and_initialize_driver end def stop_driver_if_necessary(suite_passed) #:nodoc: - failure_has_occurred unless suite_passed if @driver && stop_driver?(suite_passed) @driver.stop @driver = nil end end @@ -194,80 +192,17 @@ browser_url, 15000 ) end - def create_server_runner #:nodoc: - case @app_server_engine.to_sym - when :mongrel - create_mongrel_runner - when :webrick - create_webrick_runner - else - raise "Invalid server type: #{selenium_configuration.app_server_type}" - end + attr_reader :app_server_runner + def create_app_server_runner #:nodoc: + app_server_type = SERVER_RUNNERS[@app_server_engine.to_sym] + raise "Invalid server engine #{@app_server_engine}" unless app_server_type + @app_server_runner = app_server_type.new(self) end - def create_webrick_runner #:nodoc: - require 'webrick_server' - runner = WebrickSeleniumServerRunner.new - runner.configuration = self - runner.thread_class = Thread - runner.socket = Socket - runner.dispatch_servlet = DispatchServlet - runner.environment_path = File.expand_path("#{@rails_root}/config/environment") - runner - end - - def create_webrick_server #:nodoc: - WEBrick::HTTPServer.new({ - :Port => @internal_app_server_port, - :BindAddress => @internal_app_server_host, - :ServerType => WEBrick::SimpleServer, - :MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes, - :Logger => new_logger, - :AccessLog => [] - }) - end - def new_logger Logger.new(StringIO.new) - end - - def create_mongrel_runner #:nodoc: - runner = MongrelSeleniumServerRunner.new - runner.configuration = self - runner.thread_class = Thread - runner - end - - def create_mongrel_configurator #:nodoc: - dir = File.dirname(__FILE__) - require 'mongrel/rails' - settings = { - :host => internal_app_server_host, - :port => internal_app_server_port, - :cwd => @rails_root, - :log_file => "#{@rails_root}/log/mongrel.log", - :pid_file => "#{@rails_root}/log/mongrel.pid", - :environment => @rails_env, - :docroot => "#{@rails_root}/public", - :mime_map => nil, - :daemon => false, - :debug => false, - :includes => ["mongrel"], - :config_script => nil - } - - configurator = Mongrel::Rails::RailsConfigurator.new(settings) do - log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}" - end - configurator - end - - protected - # Sets the failure state to true - def failure_has_occurred - @failure_has_occurred = true end end end \ No newline at end of file