diff --git a/lib/webrat/selenium/application_server.rb b/lib/webrat/selenium/application_server.rb deleted file mode 100644 index 75ea0b3..0000000 --- a/lib/webrat/selenium/application_server.rb +++ /dev/null @@ -1,45 +0,0 @@ -module Webrat - module Selenium - - class ApplicationServer - - include Webrat::Selenium::SilenceStream - - def boot - start - wait - stop_at_exit - end - - def stop_at_exit - at_exit do - stop - end - end - - def wait - $stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... " - wait_for_socket - $stderr.print "Ready!\n" - end - - def wait_for_socket - silence_stream(STDOUT) do - TCPSocket.wait_for_service_with_timeout \ - :host => Webrat.configuration.application_address, - :port => Webrat.configuration.application_port.to_i, - :timeout => 30 # seconds - end - rescue SocketError - fail - end - - def prepare_pid_file(file_path, pid_file_name) - FileUtils.mkdir_p File.expand_path(file_path) - File.expand_path("#{file_path}/#{pid_file_name}") - end - - end - - end -end diff --git a/lib/webrat/selenium/application_servers.rb b/lib/webrat/selenium/application_servers.rb index 45c5ca4..cd0234b 100644 --- a/lib/webrat/selenium/application_servers.rb +++ b/lib/webrat/selenium/application_servers.rb @@ -1,3 +1,4 @@ +require "webrat/selenium/application_servers/base" require "webrat/selenium/application_servers/sinatra" require "webrat/selenium/application_servers/merb" require "webrat/selenium/application_servers/rails" diff --git a/lib/webrat/selenium/application_servers/base.rb b/lib/webrat/selenium/application_servers/base.rb new file mode 100644 index 0000000..29fda8f --- /dev/null +++ b/lib/webrat/selenium/application_servers/base.rb @@ -0,0 +1,44 @@ +module Webrat + module Selenium + module ApplicationServers + class Base + include Webrat::Selenium::SilenceStream + + def boot + start + wait + stop_at_exit + end + + def stop_at_exit + at_exit do + stop + end + end + + def wait + $stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... " + wait_for_socket + $stderr.print "Ready!\n" + end + + def wait_for_socket + silence_stream(STDOUT) do + TCPSocket.wait_for_service_with_timeout \ + :host => Webrat.configuration.application_address, + :port => Webrat.configuration.application_port.to_i, + :timeout => 30 # seconds + end + rescue SocketError + fail + end + + def prepare_pid_file(file_path, pid_file_name) + FileUtils.mkdir_p File.expand_path(file_path) + File.expand_path("#{file_path}/#{pid_file_name}") + end + + end + end + end +end diff --git a/lib/webrat/selenium/application_servers/external.rb b/lib/webrat/selenium/application_servers/external.rb index 187cfff..a39bc31 100644 --- a/lib/webrat/selenium/application_servers/external.rb +++ b/lib/webrat/selenium/application_servers/external.rb @@ -1,7 +1,7 @@ module Webrat module Selenium module ApplicationServers - class External < ApplicationServer + class External < Webrat::Selenium::ApplicationServers::Base def start warn "Webrat Ignoring Start Of Application Server Due to External Mode" end diff --git a/lib/webrat/selenium/application_servers/merb.rb b/lib/webrat/selenium/application_servers/merb.rb index 163b7f0..fd5d9d8 100644 --- a/lib/webrat/selenium/application_servers/merb.rb +++ b/lib/webrat/selenium/application_servers/merb.rb @@ -1,7 +1,7 @@ module Webrat module Selenium module ApplicationServers - class Merb < ApplicationServer + class Merb < Webrat::Selenium::ApplicationServers::Base def start system start_command diff --git a/lib/webrat/selenium/application_servers/rails.rb b/lib/webrat/selenium/application_servers/rails.rb index 1561334..687abef 100644 --- a/lib/webrat/selenium/application_servers/rails.rb +++ b/lib/webrat/selenium/application_servers/rails.rb @@ -1,8 +1,7 @@ module Webrat module Selenium - module ApplicationServers - class Rails < ApplicationServer + class Rails < Webrat::Selenium::ApplicationServers::Base def start system start_command diff --git a/lib/webrat/selenium/application_servers/sinatra.rb b/lib/webrat/selenium/application_servers/sinatra.rb index cf04aef..dc991a3 100644 --- a/lib/webrat/selenium/application_servers/sinatra.rb +++ b/lib/webrat/selenium/application_servers/sinatra.rb @@ -1,7 +1,7 @@ module Webrat module Selenium module ApplicationServers - class Sinatra < ApplicationServer + class Sinatra < Webrat::Selenium::ApplicationServers::Base def start fork do diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 6a0324e..630f61b 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -1,7 +1,7 @@ require "webrat/core/save_and_open_page" require "webrat/selenium/selenium_rc_server" require "webrat/selenium/application_server_factory" -require "webrat/selenium/application_server" +require "webrat/selenium/application_servers/base" module Webrat class TimeoutError < WebratError diff --git a/spec/public/selenium/application_server_factory_spec.rb b/spec/public/selenium/application_server_factory_spec.rb index 259fd44..56c562c 100644 --- a/spec/public/selenium/application_server_factory_spec.rb +++ b/spec/public/selenium/application_server_factory_spec.rb @@ -2,7 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require "webrat/selenium/silence_stream" require "webrat/selenium/application_server_factory" -require "webrat/selenium/application_server" require "webrat/selenium/application_servers" diff --git a/spec/public/selenium/application_servers/external_spec.rb b/spec/public/selenium/application_servers/external_spec.rb index 7c3faca..353ac9e 100644 --- a/spec/public/selenium/application_servers/external_spec.rb +++ b/spec/public/selenium/application_servers/external_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') -require "webrat/selenium/application_server" +require "webrat/selenium/application_servers/base" require "webrat/selenium/application_servers/external" describe Webrat::Selenium::ApplicationServers::External do