Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for running Rails under the 'thin' webserver

This patch is based on the original code by Marcello Nuccio and the
advice by gaffo on how to reorganize it into a patch:

https://webrat.lighthouseapp.com/projects/10503/tickets/250-cant-configure-webrat-to-use-eg-thin-instead-of-mongrel

Supporting 'thin' provides a number of advantages:

  1) It allows Webrat to be used with Rails application prefixes.
  2) It allows Webrat to be used with Bundler 0.9.  Currently, this
     fails with the following symptoms, because of interactions among
     Mongrel, gem_plugin and bundler:

http://stackoverflow.com/questions/2360683/cucumber-and-webrat-in-selenium-mode-cant-start-mongrel-rails-when-using-gem-bu

The unit tests for RailsThin are based on the original ones for the
Rails class.

To use this new thin support, simply specify:

  config.application_framework = :rails_thin
  • Loading branch information...
commit 25e463f852446ab7305e63b849146a2a82b6498d 1 parent 80ea640
@emk authored
View
1  Gemfile
@@ -17,3 +17,4 @@ gem "launchy", "0.3.3"
gem "rack-test", "0.5.2"
gem "sinatra", "0.9.4"
gem "mongrel", "1.1.5"
+gem "thin", "1.2.7"
View
3  lib/webrat/selenium/application_server_factory.rb
@@ -14,6 +14,9 @@ def self.app_server_instance
when :rails
require "webrat/selenium/application_servers/rails"
return Webrat::Selenium::ApplicationServers::Rails.new
+ when :rails_thin
+ require "webrat/selenium/application_servers/rails_thin"
+ return Webrat::Selenium::ApplicationServers::RailsThin.new
when :external
require "webrat/selenium/application_servers/external"
return Webrat::Selenium::ApplicationServers::External.new
View
49 lib/webrat/selenium/application_servers/rails_thin.rb
@@ -0,0 +1,49 @@
+require "webrat/selenium/application_servers/base"
+
+module Webrat
+ module Selenium
+ module ApplicationServers
+ class RailsThin < Webrat::Selenium::ApplicationServers::Base
+
+ 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 Thin application server... exiting!"
+ $stderr.puts
+ $stderr.puts "Verify you can start a Rails Thin 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", "thin_selenium.pid")
+ end
+
+ def start_command
+ if ActionController::Base.relative_url_root
+ prefix = "--prefix #{ActionController::Base.relative_url_root}"
+ else
+ prefix = ""
+ end
+ "thin start -A rails -d #{prefix} --chdir #{RAILS_ROOT} --port #{Webrat.configuration.application_port} --environment #{Webrat.configuration.application_environment} --pid #{pid_file}"
+ end
+
+ def stop_command
+ "thin stop --chdir #{RAILS_ROOT} --pid #{pid_file}"
+ end
+
+ end
+ end
+ end
+end
View
26 spec/private/selenium/application_servers/rails_thin_spec.rb
@@ -0,0 +1,26 @@
+require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
+require "webrat/selenium/application_servers/rails_thin"
+
+RAILS_ROOT = "." unless defined?(RAILS_ROOT)
+
+describe Webrat::Selenium::ApplicationServers::RailsThin do
+ include Webrat::Selenium::SilenceStream
+
+ before do
+ @server = Webrat::Selenium::ApplicationServers::RailsThin.new
+ # require "rubygems"; require "ruby-debug"; Debugger.start; debugger
+ @server.stub!(:system)
+ @server.stub!(:at_exit)
+ end
+
+ describe "boot" do
+ it "should wait for the server to start on 0.0.0.0" do
+ TCPSocket.should_receive(:wait_for_service_with_timeout).
+ with(hash_including(:host => "0.0.0.0"))
+
+ silence_stream(STDERR) do
+ @server.boot
+ end
+ end
+ end
+end
View
8 spec/public/selenium/application_server_factory_spec.rb
@@ -31,6 +31,14 @@
Webrat::Selenium::ApplicationServerFactory.app_server_instance
end
+ it "should require and create a rails server in rails thin mode" do
+ server = mock(Webrat::Selenium::ApplicationServers::RailsThin)
+ Webrat.configuration.application_framework = :rails_thin
+ Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/rails_thin")
+ Webrat::Selenium::ApplicationServers::RailsThin.should_receive(:new).and_return(server)
+ Webrat::Selenium::ApplicationServerFactory.app_server_instance
+ end
+
it "should require and create a rails server in external mode" do
server = mock(Webrat::Selenium::ApplicationServers::External)
Webrat.configuration.application_framework = :external
Please sign in to comment.
Something went wrong with that request. Please try again.