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

This commit is contained in:
Corey Donohoe 2009-02-11 11:17:43 -07:00
parent 8fbcbef180
commit 4bf49a5163
2 changed files with 20 additions and 6 deletions

View File

@ -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'

View File

@ -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