Skip to content

Commit

Permalink
make sure starting a daemon works with trinidad.rb config not just tr…
Browse files Browse the repository at this point in the history
…inidad.yml (closes #7)
  • Loading branch information
kares committed Jan 20, 2012
1 parent 2cff9fc commit 120d56e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/trinidad_init_services.rb
Expand Up @@ -11,11 +11,11 @@ def init
def setup?
true
end

def start
opts = Trinidad::CommandLineParser.parse(ARGV)
opts[:trap] = false
@server = Trinidad::Server.new(opts)
def start(args = ARGV)
Trinidad::CommandLineParser.parse(args)
Trinidad.configuration.trap = false
@server = Trinidad::Server.new
@server.start
end

Expand Down
6 changes: 6 additions & 0 deletions spec/stubs/trinidad.rb
@@ -0,0 +1,6 @@
Trinidad.configure do |config|
config.port = 3002
config.address = '127.0.0.1'
config.jruby_min_runtimes = 1
config.jruby_max_runtimes = 2
end
5 changes: 5 additions & 0 deletions spec/stubs/trinidad.yml
@@ -0,0 +1,5 @@
---
port: 3001
context_path: "/foo"
jruby_min_runtimes: 1
jruby_max_runtimes: 1
69 changes: 69 additions & 0 deletions spec/trinidad_daemon_spec.rb
@@ -0,0 +1,69 @@
require File.expand_path('spec_helper', File.dirname(__FILE__))
require 'trinidad_init_services'

Trinidad::Daemon.module_eval do
def server; @server; end
end

describe Trinidad::Daemon do

after :each do
Trinidad.configuration = nil
end

it "starts a configured server" do
Trinidad::Server.any_instance.expects(:start)
Trinidad::Daemon.start([])
Trinidad::Daemon.server.should be_a(Trinidad::Server)
Trinidad::Daemon.server.config.should be_a(Trinidad::Configuration)
end

context "started with a yaml config" do

before :each do
Trinidad::Server.any_instance.stubs(:start)
config = File.expand_path('stubs/trinidad.yml', File.dirname(__FILE__))
Trinidad::Daemon.start([ '--config', config ])
@config = Trinidad::Daemon.server.config
end

it "is configured without signal trap" do
@config[:trap].should == false
end

it "is configured according to .yml" do
@config[:port].should == 3001
@config[:context_path].should == '/foo'
@config[:jruby_min_runtimes].should == 1
@config[:jruby_max_runtimes].should == 1

@config[:address].should == 'localhost'
end

end

context "started with a ruby config" do

before :each do
Trinidad::Server.any_instance.stubs(:start)
config = File.expand_path('stubs/trinidad.rb', File.dirname(__FILE__))
Trinidad::Daemon.start([ '--config', config ])
@config = Trinidad::Daemon.server.config
end

it "is configured without signal trap" do
@config[:trap].should == false
end

it "is configured according to .rb" do
@config[:port].should == 3002
@config[:address].should == '127.0.0.1'
@config[:jruby_min_runtimes].should == 1
@config[:jruby_max_runtimes].should == 2

@config[:context_path].should == '/'
end

end

end
2 changes: 1 addition & 1 deletion spec/trinidad_init_services/configuration_spec.rb
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require File.expand_path('spec_helper', File.join(File.dirname(__FILE__), '..'))
require 'yaml'

describe Trinidad::InitServices::Configuration do
Expand Down
2 changes: 1 addition & 1 deletion trinidad_init_services.gemspec
Expand Up @@ -44,7 +44,7 @@ Gem::Specification.new do |s|

## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
s.add_dependency('trinidad', '>=1.2.2')
s.add_dependency('trinidad', '>= 1.3.2')

s.add_development_dependency('rspec', '>= 2.7.1')
s.add_development_dependency('mocha', '>= 0.10')
Expand Down

0 comments on commit 120d56e

Please sign in to comment.