From 4bf49a516320ea74d6948036cbb4312499f84083 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Wed, 11 Feb 2009 11:17:43 -0700 Subject: [PATCH] allow picking your appserver type via a configuration option, not discovering framework specific files in the current working directory. also start rack apps with the application port parameter --- lib/webrat/core/configuration.rb | 6 +++++- lib/webrat/selenium.rb | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/webrat/core/configuration.rb b/lib/webrat/core/configuration.rb index dea1925..685a248 100755 --- a/lib/webrat/core/configuration.rb +++ b/lib/webrat/core/configuration.rb @@ -39,6 +39,9 @@ module Webrat webrat_deprecate :selenium_port, :application_port webrat_deprecate :selenium_port=, :application_port= + # Which underlying appserver are we testing with selenium + attr_accessor :application_type + # Which server the application is running on for selenium testing? Defaults to localhost attr_accessor :application_address @@ -61,6 +64,7 @@ module Webrat self.application_environment = :selenium self.application_port = 3001 self.application_address = 'localhost' + self.application_type = 'rails' self.selenium_server_port = 4444 self.infinite_redirect_limit = 10 self.selenium_browser_key = '*firefox' @@ -91,4 +95,4 @@ module Webrat end -end \ No newline at end of file +end diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 87606ca..e140087 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -34,23 +34,33 @@ module Webrat end def self.start_app_server #:nodoc: - if File.exists?('config.ru') + case Webrat.configuration.application_type + when :sinatra fork do File.open('rack.pid', 'w') { |fp| fp.write Process.pid } - exec 'rackup', File.expand_path(Dir.pwd + '/config.ru') + exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s end - else + when :merb + fork do + exec 'merb', '-d' + end + else # rails system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") end TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i end def self.stop_app_server #:nodoc: - if File.exists?('config.ru') + case Webrat.configuration.application_type + when :sinatra pid = File.read('rack.pid') system("kill -9 #{pid}") FileUtils.rm_f 'rack.pid' - else + when :merb + pid = File.read('log/merb.4000.pid') + system("kill -9 #{pid}") + FileUtils.rm_f 'log/merb.4000.pid' + else # rails system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" end end