Webrat.configuration.application_type => Webrat.configuration.application_framework

This commit is contained in:
Corey Donohoe 2009-02-15 14:40:17 -07:00
parent 7692930769
commit 69dfa5022a
3 changed files with 11 additions and 13 deletions

View File

@ -39,8 +39,8 @@ module Webrat
webrat_deprecate :selenium_port, :application_port webrat_deprecate :selenium_port, :application_port
webrat_deprecate :selenium_port=, :application_port= webrat_deprecate :selenium_port=, :application_port=
# Which underlying appserver are we testing with selenium # Which underlying app framework we're testing with selenium
attr_accessor :application_type attr_accessor :application_framework
# Which server the application is running on for selenium testing? Defaults to localhost # Which server the application is running on for selenium testing? Defaults to localhost
attr_accessor :application_address attr_accessor :application_address

View File

@ -34,16 +34,14 @@ module Webrat
end end
def self.start_app_server #:nodoc: def self.start_app_server #:nodoc:
case Webrat.configuration.application_type case Webrat.configuration.application_framework
when :sinatra when :sinatra
fork do fork do
File.open('rack.pid', 'w') { |fp| fp.write Process.pid } 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 exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
end end
when :merb when :merb
fork do system("merb -d -p #{Webrat.configuration.application_port}"
exec 'merb', '-d', '-p', Webrat.configuration.application_port
end
else # rails else # rails
system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &") system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
end end
@ -51,7 +49,7 @@ module Webrat
end end
def self.stop_app_server #:nodoc: def self.stop_app_server #:nodoc:
case Webrat.configuration.application_type case Webrat.configuration.application_framework
when :sinatra when :sinatra
pid = File.read('rack.pid') pid = File.read('rack.pid')
system("kill -9 #{pid}") system("kill -9 #{pid}")

View File

@ -8,7 +8,7 @@ RAILS_ROOT = "/"
describe Webrat, "Selenium" do describe Webrat, "Selenium" do
describe "start_app_server" do describe "start_app_server" do
after(:each) { Webrat.configuration.application_type = :rails } after(:each) { Webrat.configuration.application_framework = :rails }
describe "ruby on rails" do describe "ruby on rails" do
it "should start the app server with correct config options" do it "should start the app server with correct config options" do
pid_file = "file" pid_file = "file"
@ -20,7 +20,7 @@ describe Webrat, "Selenium" do
end end
describe "merb" do describe "merb" do
it "should start the app server with correct config options" do it "should start the app server with correct config options" do
Webrat.configuration.application_type = :merb Webrat.configuration.application_framework = :merb
Webrat.should_receive(:fork) Webrat.should_receive(:fork)
# Kernel.should_receive(:exec).with(['merb', '-d', '-p', Webrat.configuration.application_port]) # 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) TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
@ -30,7 +30,7 @@ describe Webrat, "Selenium" do
describe "sinatra" do describe "sinatra" do
it "should start the app server with correct config options" do it "should start the app server with correct config options" do
rackup_file = File.expand_path(Dir.pwd + '/config.ru') rackup_file = File.expand_path(Dir.pwd + '/config.ru')
Webrat.configuration.application_type = :sinatra Webrat.configuration.application_framework = :sinatra
Webrat.should_receive(:fork) Webrat.should_receive(:fork)
# Kernel.should_receive(:exec).with(['rackup', rackup_file, '-p', Webrat.configuration.application_port]) # 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) TCPSocket.should_receive(:wait_for_service).with(:host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i)
@ -40,7 +40,7 @@ describe Webrat, "Selenium" do
end end
end end
describe "stop_app_server" do describe "stop_app_server" do
after(:each) { Webrat.configuration.application_type = :rails } after(:each) { Webrat.configuration.application_framework = :rails }
describe "ruby on rails" do describe "ruby on rails" do
it "should stop the app server with correct config options" do it "should stop the app server with correct config options" do
pid_file = RAILS_ROOT+'/tmp/pids/mongrel_selenium.pid' pid_file = RAILS_ROOT+'/tmp/pids/mongrel_selenium.pid'
@ -50,7 +50,7 @@ describe Webrat, "Selenium" do
end end
describe "merb" do describe "merb" do
it "should stop the app server with correct config options" do it "should stop the app server with correct config options" do
Webrat.configuration.application_type = :merb Webrat.configuration.application_framework = :merb
File.should_receive(:read).with('log/merb.3001.pid').and_return('666') File.should_receive(:read).with('log/merb.3001.pid').and_return('666')
Webrat.should_receive(:system).with("kill -9 666") Webrat.should_receive(:system).with("kill -9 666")
Webrat.stop_app_server Webrat.stop_app_server
@ -58,7 +58,7 @@ describe Webrat, "Selenium" do
end end
describe "sinatra" do describe "sinatra" do
it "should stop the app server with correct config options" do it "should stop the app server with correct config options" do
Webrat.configuration.application_type = :sinatra Webrat.configuration.application_framework = :sinatra
File.should_receive(:read).with('rack.pid').and_return('666') File.should_receive(:read).with('rack.pid').and_return('666')
Webrat.should_receive(:system).with("kill -9 666") Webrat.should_receive(:system).with("kill -9 666")
Webrat.stop_app_server Webrat.stop_app_server