small fixup for sinatra + selenium, use rackup instead of mongrel_rails if config.ru exists

This commit is contained in:
Corey Donohoe 2009-02-11 09:25:39 -07:00
parent 24eab77ecd
commit 82eabc31ee
2 changed files with 40 additions and 14 deletions

View File

@ -25,15 +25,31 @@ module Webrat
::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
end end
def self.pid_file
if File.exists?('config.ru')
prepare_pid_file(Dir.pwd, 'rack.pid')
else
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
end
end
def self.start_app_server #:nodoc: def self.start_app_server #:nodoc:
pid_file = prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid") if File.exists?('config.ru')
system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") fork do
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-P', 'rack.pid'
end
else
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 TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
end end
def self.stop_app_server #:nodoc: def self.stop_app_server #:nodoc:
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid") if File.exists?('config.ru')
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" system("kill -9 `cat rack.pid`")
else
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
end
end end
def self.prepare_pid_file(file_path, pid_file_name) def self.prepare_pid_file(file_path, pid_file_name)
@ -90,10 +106,10 @@ module Webrat
end end
end end
module ActionController #:nodoc: #module ActionController #:nodoc:
IntegrationTest.class_eval do # IntegrationTest.class_eval do
include Webrat::Methods # include Webrat::Methods
include Webrat::Selenium::Methods # include Webrat::Selenium::Methods
include Webrat::Selenium::Matchers # include Webrat::Selenium::Matchers
end # end
end #end

View File

@ -179,11 +179,21 @@ module Webrat
end end
protected protected
def silence_stream(stream)
old_stream = stream.dup
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.sync = true
yield
ensure
stream.reopen(old_stream)
end
def setup #:nodoc: def setup #:nodoc:
silence_stream(STDOUT) do silence_stream(STDOUT) do
Webrat.start_selenium_server silence_stream(STDERR) do
Webrat.start_app_server Webrat.start_selenium_server
Webrat.start_app_server
end
end end
create_browser create_browser