From 82eabc31ee7b0b54ae2e741f241d7ce22c7af27e Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Wed, 11 Feb 2009 09:25:39 -0700 Subject: [PATCH] small fixup for sinatra + selenium, use rackup instead of mongrel_rails if config.ru exists --- lib/webrat/selenium.rb | 38 ++++++++++++++++++------- lib/webrat/selenium/selenium_session.rb | 16 +++++++++-- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index d245191..bf0beb0 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -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 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: - pid_file = prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid") - system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") + if File.exists?('config.ru') + 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 end def self.stop_app_server #:nodoc: - pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid") - system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" + if File.exists?('config.ru') + system("kill -9 `cat rack.pid`") + else + system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" + end end def self.prepare_pid_file(file_path, pid_file_name) @@ -90,10 +106,10 @@ module Webrat end end -module ActionController #:nodoc: - IntegrationTest.class_eval do - include Webrat::Methods - include Webrat::Selenium::Methods - include Webrat::Selenium::Matchers - end -end +#module ActionController #:nodoc: +# IntegrationTest.class_eval do +# include Webrat::Methods +# include Webrat::Selenium::Methods +# include Webrat::Selenium::Matchers +# end +#end diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 11438da..6880957 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -179,11 +179,21 @@ module Webrat end 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: silence_stream(STDOUT) do - Webrat.start_selenium_server - Webrat.start_app_server + silence_stream(STDERR) do + Webrat.start_selenium_server + Webrat.start_app_server + end end create_browser @@ -234,4 +244,4 @@ module Webrat end end end -end \ No newline at end of file +end