diff --git a/lib/webrat/selenium/application_server_factory.rb b/lib/webrat/selenium/application_server_factory.rb index 76f3dfe..7a184aa 100644 --- a/lib/webrat/selenium/application_server_factory.rb +++ b/lib/webrat/selenium/application_server_factory.rb @@ -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 diff --git a/lib/webrat/selenium/application_servers.rb b/lib/webrat/selenium/application_servers.rb index 59c68ac..45c5ca4 100644 --- a/lib/webrat/selenium/application_servers.rb +++ b/lib/webrat/selenium/application_servers.rb @@ -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" \ No newline at end of file diff --git a/lib/webrat/selenium/application_servers/merb.rb b/lib/webrat/selenium/application_servers/merb.rb new file mode 100644 index 0000000..163b7f0 --- /dev/null +++ b/lib/webrat/selenium/application_servers/merb.rb @@ -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 diff --git a/lib/webrat/selenium/application_servers/rails.rb b/lib/webrat/selenium/application_servers/rails.rb new file mode 100644 index 0000000..1561334 --- /dev/null +++ b/lib/webrat/selenium/application_servers/rails.rb @@ -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 diff --git a/lib/webrat/selenium/application_servers/sinatra.rb b/lib/webrat/selenium/application_servers/sinatra.rb new file mode 100644 index 0000000..cf04aef --- /dev/null +++ b/lib/webrat/selenium/application_servers/sinatra.rb @@ -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 diff --git a/lib/webrat/selenium/merb_application_server.rb b/lib/webrat/selenium/merb_application_server.rb deleted file mode 100644 index a6c6c34..0000000 --- a/lib/webrat/selenium/merb_application_server.rb +++ /dev/null @@ -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 diff --git a/lib/webrat/selenium/rails_application_server.rb b/lib/webrat/selenium/rails_application_server.rb deleted file mode 100644 index fd305a2..0000000 --- a/lib/webrat/selenium/rails_application_server.rb +++ /dev/null @@ -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 diff --git a/lib/webrat/selenium/sinatra_application_server.rb b/lib/webrat/selenium/sinatra_application_server.rb deleted file mode 100644 index d6c3659..0000000 --- a/lib/webrat/selenium/sinatra_application_server.rb +++ /dev/null @@ -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 diff --git a/spec/public/selenium/application_server_factory_spec.rb b/spec/public/selenium/application_server_factory_spec.rb index ceae5e1..259fd44 100644 --- a/spec/public/selenium/application_server_factory_spec.rb +++ b/spec/public/selenium/application_server_factory_spec.rb @@ -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