refactor>moved the app servers to a directory

This commit is contained in:
Mike Gaffney 2009-06-04 15:13:54 -05:00
parent 70fadbe7fc
commit 1910204974
9 changed files with 144 additions and 143 deletions

View File

@ -6,14 +6,14 @@ module Webrat
def self.app_server_instance
case Webrat.configuration.application_framework
when :sinatra
require "webrat/selenium/sinatra_application_server"
return SinatraApplicationServer.new
require "webrat/selenium/application_servers/sinatra"
return Webrat::Selenium::ApplicationServers::Sinatra.new
when :merb
require "webrat/selenium/merb_application_server"
return MerbApplicationServer.new
require "webrat/selenium/application_servers/merb"
return Webrat::Selenium::ApplicationServers::Merb.new
when :rails
require "webrat/selenium/rails_application_server"
return RailsApplicationServer.new
require "webrat/selenium/application_servers/rails"
return Webrat::Selenium::ApplicationServers::Rails.new
when :external
require "webrat/selenium/application_servers/external"
return Webrat::Selenium::ApplicationServers::External.new

View File

@ -1,4 +1,4 @@
require "webrat/selenium/sinatra_application_server"
require "webrat/selenium/merb_application_server"
require "webrat/selenium/rails_application_server"
require "webrat/selenium/application_servers/sinatra"
require "webrat/selenium/application_servers/merb"
require "webrat/selenium/application_servers/rails"
require "webrat/selenium/application_servers/external"

View File

@ -0,0 +1,48 @@
module Webrat
module Selenium
module ApplicationServers
class Merb < ApplicationServer
def start
system start_command
end
def stop
silence_stream(STDOUT) do
pid = File.read(pid_file)
system("kill -9 #{pid}")
FileUtils.rm_f pid_file
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Merb application server... exiting!"
$stderr.puts
$stderr.puts "Verify you can start a Merb server on port #{Webrat.configuration.application_port} with the following command:"
$stderr.puts
$stderr.puts " #{start_command}"
exit
end
def pid_file
"log/merb.#{Webrat.configuration.application_port}.pid"
end
def start_command
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
end
def merb_command
if File.exist?('bin/merb')
merb_cmd = 'bin/merb'
else
merb_cmd = 'merb'
end
end
end
end
end
end

View File

@ -0,0 +1,43 @@
module Webrat
module Selenium
module ApplicationServers
class Rails < ApplicationServer
def start
system start_command
end
def stop
silence_stream(STDOUT) do
system stop_command
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Rails application server... exiting!"
$stderr.puts
$stderr.puts "Verify you can start a Rails server on port #{Webrat.configuration.application_port} with the following command:"
$stderr.puts
$stderr.puts " #{start_command}"
exit
end
def pid_file
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
end
def start_command
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
end
def stop_command
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
end
end
end
end
end

View File

@ -0,0 +1,35 @@
module Webrat
module Selenium
module ApplicationServers
class Sinatra < ApplicationServer
def start
fork do
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
end
end
def stop
silence_stream(STDOUT) do
pid = File.read(pid_file)
system("kill -9 #{pid}")
FileUtils.rm_f pid_file
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
exit
end
def pid_file
prepare_pid_file(Dir.pwd, 'rack.pid')
end
end
end
end
end

View File

@ -1,48 +0,0 @@
module Webrat
module Selenium
class MerbApplicationServer < ApplicationServer
def start
system start_command
end
def stop
silence_stream(STDOUT) do
pid = File.read(pid_file)
system("kill -9 #{pid}")
FileUtils.rm_f pid_file
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Merb application server... exiting!"
$stderr.puts
$stderr.puts "Verify you can start a Merb server on port #{Webrat.configuration.application_port} with the following command:"
$stderr.puts
$stderr.puts " #{start_command}"
exit
end
def pid_file
"log/merb.#{Webrat.configuration.application_port}.pid"
end
def start_command
"#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
end
def merb_command
if File.exist?('bin/merb')
merb_cmd = 'bin/merb'
else
merb_cmd = 'merb'
end
end
end
end
end

View File

@ -1,42 +0,0 @@
module Webrat
module Selenium
class RailsApplicationServer < ApplicationServer
def start
system start_command
end
def stop
silence_stream(STDOUT) do
system stop_command
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Rails application server... exiting!"
$stderr.puts
$stderr.puts "Verify you can start a Rails server on port #{Webrat.configuration.application_port} with the following command:"
$stderr.puts
$stderr.puts " #{start_command}"
exit
end
def pid_file
prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
end
def start_command
"mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
end
def stop_command
"mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
end
end
end
end

View File

@ -1,35 +0,0 @@
module Webrat
module Selenium
class SinatraApplicationServer < ApplicationServer
def start
fork do
File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
end
end
def stop
silence_stream(STDOUT) do
pid = File.read(pid_file)
system("kill -9 #{pid}")
FileUtils.rm_f pid_file
end
end
def fail
$stderr.puts
$stderr.puts
$stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
exit
end
def pid_file
prepare_pid_file(Dir.pwd, 'rack.pid')
end
end
end
end

View File

@ -9,26 +9,26 @@ require "webrat/selenium/application_servers"
describe Webrat::Selenium::ApplicationServerFactory do
it "should require and create a sinatra server in sinatra mode" do
server = mock(Webrat::Selenium::SinatraApplicationServer)
server = mock(Webrat::Selenium::ApplicationServers::Sinatra)
Webrat.configuration.application_framework = :sinatra
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/sinatra_application_server")
Webrat::Selenium::SinatraApplicationServer.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/sinatra")
Webrat::Selenium::ApplicationServers::Sinatra.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.app_server_instance.should == server
end
it "should require and create a merb server in merb mode" do
server = mock(Webrat::Selenium::MerbApplicationServer)
server = mock(Webrat::Selenium::ApplicationServers::Merb)
Webrat.configuration.application_framework = :merb
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/merb_application_server")
Webrat::Selenium::MerbApplicationServer.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/merb")
Webrat::Selenium::ApplicationServers::Merb.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.app_server_instance
end
it "should require and create a rails server in rails mode" do
server = mock(Webrat::Selenium::RailsApplicationServer)
server = mock(Webrat::Selenium::ApplicationServers::Rails)
Webrat.configuration.application_framework = :rails
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/rails_application_server")
Webrat::Selenium::RailsApplicationServer.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/rails")
Webrat::Selenium::ApplicationServers::Rails.should_receive(:new).and_return(server)
Webrat::Selenium::ApplicationServerFactory.app_server_instance
end