From 9066d2a9cdd3ec95812cab46cdd23a5069a556c4 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Fri, 13 Feb 2009 20:26:44 -0700 Subject: [PATCH] add specs for starting and stopping appservers, covers rails, sinatra and merb --- spec/private/selenium/selenium_spec.rb | 65 +++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/spec/private/selenium/selenium_spec.rb b/spec/private/selenium/selenium_spec.rb index 62235d6..efeb7fe 100644 --- a/spec/private/selenium/selenium_spec.rb +++ b/spec/private/selenium/selenium_spec.rb @@ -7,13 +7,64 @@ RAILS_ROOT = "/" describe Webrat, "Selenium" do - - it "should start the app server with correct config options" do - pid_file = "file" - Webrat.should_receive(:prepare_pid_file).with("#{RAILS_ROOT}/tmp/pids","mongrel_selenium.pid").and_return pid_file - Webrat.should_receive(:system).with("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") - TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i) - Webrat.start_app_server + describe "start_app_server" do + after(:each) { Webrat.configuration.application_type = :rails } + describe "ruby on rails" do + it "should start the app server with correct config options" do + pid_file = "file" + Webrat.should_receive(:prepare_pid_file).with("#{RAILS_ROOT}/tmp/pids","mongrel_selenium.pid").and_return pid_file + Webrat.should_receive(:system).with("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") + TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i) + Webrat.start_app_server + end + end + describe "merb" do + it "should start the app server with correct config options" do + Webrat.configuration.application_type = :merb + Webrat.should_receive(:fork) +# Kernel.should_receive(:exec).with(['merb', '-d', '-p', Webrat.configuration.application_port]) + TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i) + Webrat.start_app_server + end + end + describe "sinatra" do + it "should start the app server with correct config options" do + rackup_file = File.expand_path(Dir.pwd + '/config.ru') + Webrat.configuration.application_type = :sinatra + Webrat.should_receive(:fork) +# Kernel.should_receive(:exec).with(['rackup', rackup_file, '-p', Webrat.configuration.application_port]) + TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i) + Webrat.start_app_server + FileUtils.rm_f 'rack.pid' + end + end + end + describe "stop_app_server" do + after(:each) { Webrat.configuration.application_type = :rails } + describe "ruby on rails" do + it "should stop the app server with correct config options" do + pid_file = RAILS_ROOT+'/tmp/pids/mongrel_selenium.pid' + Webrat.should_receive(:system).with("mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}") + Webrat.stop_app_server + end + end + describe "merb" do + it "should stop the app server with correct config options" do + Webrat.configuration.application_type = :merb + File.should_receive(:read).with('log/merb.4000.pid').and_return('666') + Webrat.should_receive(:system).with("kill -9 666") + Webrat.stop_app_server + end + end + describe "sinatra" do + it "should stop the app server with correct config options" do + Webrat.configuration.application_type = :sinatra + File.should_receive(:read).with('rack.pid').and_return('666') + Webrat.should_receive(:system).with("kill -9 666") + Webrat.stop_app_server + FileUtils.rm_f 'rack.pid' + end + end end it 'prepare_pid_file' do