Skip to content

Commit

Permalink
small fixup for sinatra + selenium, use rackup instead of mongrel_rai…
Browse files Browse the repository at this point in the history
…ls if config.ru exists
  • Loading branch information
atmos committed Feb 11, 2009
1 parent 24eab77 commit 82eabc3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
38 changes: 27 additions & 11 deletions lib/webrat/selenium.rb
Expand Up @@ -25,15 +25,31 @@ def self.stop_selenium_server #:nodoc:
::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)
Expand Down Expand Up @@ -90,10 +106,10 @@ def save_and_open_screengrab
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
16 changes: 13 additions & 3 deletions lib/webrat/selenium/selenium_session.rb
Expand Up @@ -179,11 +179,21 @@ def save_and_open_screengrab
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
Expand Down Expand Up @@ -234,4 +244,4 @@ def define_location_strategies #:nodoc:
end
end
end
end
end

0 comments on commit 82eabc3

Please sign in to comment.