Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Eric Kidd authored April 21, 2010
1  Gemfile
@@ -17,3 +17,4 @@ gem "launchy",          "0.3.3"
17 17
 gem "rack-test",        "0.5.2"
18 18
 gem "sinatra",          "0.9.4"
19 19
 gem "mongrel",          "1.1.5"
  20
+gem "thin",             "1.2.7"
3  lib/webrat/selenium/application_server_factory.rb
@@ -14,6 +14,9 @@ def self.app_server_instance
14 14
         when :rails
15 15
           require "webrat/selenium/application_servers/rails"
16 16
           return Webrat::Selenium::ApplicationServers::Rails.new
  17
+        when :rails_thin
  18
+          require "webrat/selenium/application_servers/rails_thin"
  19
+          return Webrat::Selenium::ApplicationServers::RailsThin.new
17 20
         when :external
18 21
           require "webrat/selenium/application_servers/external"
19 22
           return Webrat::Selenium::ApplicationServers::External.new
49  lib/webrat/selenium/application_servers/rails_thin.rb
... ...
@@ -0,0 +1,49 @@
  1
+require "webrat/selenium/application_servers/base"
  2
+
  3
+module Webrat
  4
+  module Selenium
  5
+    module ApplicationServers
  6
+      class RailsThin < Webrat::Selenium::ApplicationServers::Base
  7
+
  8
+        def start
  9
+          system start_command
  10
+        end
  11
+
  12
+        def stop
  13
+          silence_stream(STDOUT) do
  14
+            system stop_command
  15
+          end
  16
+        end
  17
+
  18
+        def fail
  19
+          $stderr.puts
  20
+          $stderr.puts
  21
+          $stderr.puts "==> Failed to boot the Rails Thin application server... exiting!"
  22
+          $stderr.puts
  23
+          $stderr.puts "Verify you can start a Rails Thin server on port #{Webrat.configuration.application_port} with the following command:"
  24
+          $stderr.puts
  25
+          $stderr.puts "    #{start_command}"
  26
+          exit
  27
+        end
  28
+
  29
+        def pid_file
  30
+          prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "thin_selenium.pid")
  31
+        end
  32
+
  33
+        def start_command
  34
+          if ActionController::Base.relative_url_root
  35
+            prefix = "--prefix #{ActionController::Base.relative_url_root}"
  36
+          else
  37
+            prefix = ""
  38
+          end
  39
+          "thin start -A rails -d #{prefix} --chdir #{RAILS_ROOT} --port #{Webrat.configuration.application_port} --environment #{Webrat.configuration.application_environment} --pid #{pid_file}"
  40
+        end
  41
+
  42
+        def stop_command
  43
+          "thin stop --chdir #{RAILS_ROOT} --pid #{pid_file}"
  44
+        end
  45
+
  46
+      end
  47
+    end
  48
+  end
  49
+end
26  spec/private/selenium/application_servers/rails_thin_spec.rb
... ...
@@ -0,0 +1,26 @@
  1
+require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
  2
+require "webrat/selenium/application_servers/rails_thin"
  3
+
  4
+RAILS_ROOT = "." unless defined?(RAILS_ROOT)
  5
+
  6
+describe Webrat::Selenium::ApplicationServers::RailsThin do
  7
+  include Webrat::Selenium::SilenceStream
  8
+
  9
+  before do
  10
+    @server = Webrat::Selenium::ApplicationServers::RailsThin.new
  11
+    # require "rubygems"; require "ruby-debug"; Debugger.start; debugger
  12
+    @server.stub!(:system)
  13
+    @server.stub!(:at_exit)
  14
+  end
  15
+
  16
+  describe "boot" do
  17
+    it "should wait for the server to start on 0.0.0.0" do
  18
+      TCPSocket.should_receive(:wait_for_service_with_timeout).
  19
+        with(hash_including(:host => "0.0.0.0"))
  20
+
  21
+      silence_stream(STDERR) do
  22
+        @server.boot
  23
+      end
  24
+    end
  25
+  end
  26
+end
8  spec/public/selenium/application_server_factory_spec.rb
@@ -31,6 +31,14 @@
31 31
     Webrat::Selenium::ApplicationServerFactory.app_server_instance
32 32
   end
33 33
 
  34
+  it "should require and create a rails server in rails thin mode" do
  35
+    server = mock(Webrat::Selenium::ApplicationServers::RailsThin)
  36
+    Webrat.configuration.application_framework = :rails_thin
  37
+    Webrat::Selenium::ApplicationServerFactory.should_receive(:require).with("webrat/selenium/application_servers/rails_thin")
  38
+    Webrat::Selenium::ApplicationServers::RailsThin.should_receive(:new).and_return(server)
  39
+    Webrat::Selenium::ApplicationServerFactory.app_server_instance
  40
+  end
  41
+
34 42
   it "should require and create a rails server in external mode" do
35 43
     server = mock(Webrat::Selenium::ApplicationServers::External)
36 44
     Webrat.configuration.application_framework = :external

0 notes on commit 25e463f

Please sign in to comment.
Something went wrong with that request. Please try again.