Permalink
Browse files

do not require rack/handler/trinidad.rb from trinidad.rb and let Rack…

…::Handler load it during `rackup -s trinidad` (users using trinidad as a library should require 'rack/handler/trinidad' explicitly )

it's much clearer since `require 'trinidad'` does not pollute a NS different from Trinidad and avoids issues such as #48

introduced in e387e98
and reverts 44f4c81 as well
  • Loading branch information...
1 parent 2e98163 commit bf26bec8ae34610cce817ba3ef2d26a354233a55 @kares kares committed Feb 20, 2012
Showing with 44 additions and 27 deletions.
  1. +1 −1 bin/trinidad
  2. +5 −0 lib/rack/handler/trinidad.rb
  3. +0 −1 lib/trinidad.rb
  4. +38 −25 spec/trinidad/rack_handler_spec.rb
View
@@ -2,5 +2,5 @@
require "trinidad"
-opts = Trinidad::CommandLineParser.parse(ARGV)
+Trinidad::CommandLineParser.parse(ARGV)
Trinidad::Server.new(Trinidad.configuration).start
@@ -1,3 +1,8 @@
+# NOTE: require 'rack/handler/trinidad' might get invoked 2 ways :
+# 1. Rack::Handler.try_require('rack/handler', 'trinidad') during rackup
+# in this case trinidad.rb might not yet been loaded
+# 2. a user require (after trinidad.rb booted) - need to load rack first
+require 'trinidad'
require 'rack/handler'
require 'rack/handler/servlet'
View
@@ -18,7 +18,6 @@
require 'trinidad/rails_web_app'
require 'trinidad/rackup_web_app'
require 'trinidad/war_web_app'
-require 'rack/handler/trinidad'
module Trinidad
VERSION = '1.3.3'
@@ -1,35 +1,48 @@
require 'spec_helper'
-describe Rack::Handler::Trinidad do
- it "registers the trinidad handler" do
- Rack::Handler.get(:trinidad).should == described_class
+describe 'Rack::Handler::Trinidad' do
+
+ it "is not loaded by default" do
+ require 'trinidad'
+ defined?(Rack::Handler::Trinidad).should be nil
end
+
+ describe 'Rack::Handler::Trinidad' do
+
+ before(:all) { require "rack/handler/trinidad" }
- it "turns the threads option into jruby min/max runtimes" do
- opts = described_class.parse_options({:threads => '2:3'})
- opts[:jruby_min_runtimes].should == 2
- opts[:jruby_max_runtimes].should == 3
- end
+ it "registers the trinidad handler" do
+ Rack::Handler.get(:trinidad).should == Rack::Handler::Trinidad
+ end
- it "uses localhost:3000 as default host:port" do
- opts = described_class.parse_options
- opts[:address].should == 'localhost'
- opts[:port].should == 3000
- end
+ it "turns the threads option into jruby min/max runtimes" do
+ opts = Rack::Handler::Trinidad.parse_options({:threads => '2:3'})
+ opts[:jruby_min_runtimes].should == 2
+ opts[:jruby_max_runtimes].should == 3
+ end
- it "accepts host:port or address:port as options" do
- opts = described_class.parse_options({:host => 'foo', :port => 4000})
- opts[:address].should == 'foo'
- opts[:port].should == 4000
+ it "uses localhost:3000 as default host:port" do
+ opts = Rack::Handler::Trinidad.parse_options
+ opts[:address].should == 'localhost'
+ opts[:port].should == 3000
+ end
- opts = described_class.parse_options({:address => 'bar', :port => 5000})
- opts[:address].should == 'bar'
- opts[:port].should == 5000
- end
+ it "accepts host:port or address:port as options" do
+ opts = Rack::Handler::Trinidad.parse_options({:host => 'foo', :port => 4000})
+ opts[:address].should == 'foo'
+ opts[:port].should == 4000
+
+ opts = Rack::Handler::Trinidad.parse_options({:address => 'bar', :port => 5000})
+ opts[:address].should == 'bar'
+ opts[:port].should == 5000
+ end
+
+ it "creates a servlet for the app" do
+ servlet = Rack::Handler::Trinidad.create_servlet(nil)
+ servlet.context.server_info.should == 'Trinidad'
+ servlet.dispatcher.should_not be nil
+ end
- it "creates a servlet for the app" do
- servlet = described_class.create_servlet(nil)
- servlet.context.server_info.should == 'Trinidad'
- servlet.dispatcher.should_not be_nil
end
+
end

0 comments on commit bf26bec

Please sign in to comment.