refactor>moved the app servers to a directory
This commit is contained in:
parent
70fadbe7fc
commit
1910204974
@ -6,14 +6,14 @@ module Webrat
|
|||||||
def self.app_server_instance
|
def self.app_server_instance
|
||||||
case Webrat.configuration.application_framework
|
case Webrat.configuration.application_framework
|
||||||
when :sinatra
|
when :sinatra
|
||||||
require "webrat/selenium/sinatra_application_server"
|
require "webrat/selenium/application_servers/sinatra"
|
||||||
return SinatraApplicationServer.new
|
return Webrat::Selenium::ApplicationServers::Sinatra.new
|
||||||
when :merb
|
when :merb
|
||||||
require "webrat/selenium/merb_application_server"
|
require "webrat/selenium/application_servers/merb"
|
||||||
return MerbApplicationServer.new
|
return Webrat::Selenium::ApplicationServers::Merb.new
|
||||||
when :rails
|
when :rails
|
||||||
require "webrat/selenium/rails_application_server"
|
require "webrat/selenium/application_servers/rails"
|
||||||
return RailsApplicationServer.new
|
return Webrat::Selenium::ApplicationServers::Rails.new
|
||||||
when :external
|
when :external
|
||||||
require "webrat/selenium/application_servers/external"
|
require "webrat/selenium/application_servers/external"
|
||||||
return Webrat::Selenium::ApplicationServers::External.new
|
return Webrat::Selenium::ApplicationServers::External.new
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require "webrat/selenium/sinatra_application_server"
|
require "webrat/selenium/application_servers/sinatra"
|
||||||
require "webrat/selenium/merb_application_server"
|
require "webrat/selenium/application_servers/merb"
|
||||||
require "webrat/selenium/rails_application_server"
|
require "webrat/selenium/application_servers/rails"
|
||||||
require "webrat/selenium/application_servers/external"
|
require "webrat/selenium/application_servers/external"
|
48
lib/webrat/selenium/application_servers/merb.rb
Normal file
48
lib/webrat/selenium/application_servers/merb.rb
Normal 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
|
43
lib/webrat/selenium/application_servers/rails.rb
Normal file
43
lib/webrat/selenium/application_servers/rails.rb
Normal 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
|
35
lib/webrat/selenium/application_servers/sinatra.rb
Normal file
35
lib/webrat/selenium/application_servers/sinatra.rb
Normal 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
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -9,26 +9,26 @@ require "webrat/selenium/application_servers"
|
|||||||
describe Webrat::Selenium::ApplicationServerFactory do
|
describe Webrat::Selenium::ApplicationServerFactory do
|
||||||
|
|
||||||
it "should require and create a sinatra server in sinatra mode" 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.configuration.application_framework = :sinatra
|
||||||
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/sinatra_application_server")
|
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/sinatra")
|
||||||
Webrat::Selenium::SinatraApplicationServer.should_receive(:new).and_return(server)
|
Webrat::Selenium::ApplicationServers::Sinatra.should_receive(:new).and_return(server)
|
||||||
Webrat::Selenium::ApplicationServerFactory.app_server_instance.should == server
|
Webrat::Selenium::ApplicationServerFactory.app_server_instance.should == server
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should require and create a merb server in merb mode" do
|
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.configuration.application_framework = :merb
|
||||||
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/merb_application_server")
|
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/merb")
|
||||||
Webrat::Selenium::MerbApplicationServer.should_receive(:new).and_return(server)
|
Webrat::Selenium::ApplicationServers::Merb.should_receive(:new).and_return(server)
|
||||||
Webrat::Selenium::ApplicationServerFactory.app_server_instance
|
Webrat::Selenium::ApplicationServerFactory.app_server_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should require and create a rails server in rails mode" do
|
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.configuration.application_framework = :rails
|
||||||
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/rails_application_server")
|
Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/rails")
|
||||||
Webrat::Selenium::RailsApplicationServer.should_receive(:new).and_return(server)
|
Webrat::Selenium::ApplicationServers::Rails.should_receive(:new).and_return(server)
|
||||||
Webrat::Selenium::ApplicationServerFactory.app_server_instance
|
Webrat::Selenium::ApplicationServerFactory.app_server_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user