Permalink
Browse files

Add option to start on alternate port, add spec for smoke testing HTTP

server functionality
  • Loading branch information...
1 parent 813dbad commit e574916aaeb0185e2481f02c1da8314f35518cc2 @paulcbetts committed Jun 29, 2008
Showing with 28 additions and 6 deletions.
  1. +15 −5 lib/main.rb
  2. +13 −1 spec/main_spec.rb
View
@@ -50,6 +50,7 @@
AllowedFiletypes = ['.avi', '.mov', '.mp4', '.wmv']
Thread.abort_on_exception = true
+trap("USR1") { dump_stacks }
class Yikes < Logger::Application
include Singleton
@@ -93,6 +94,10 @@ def parse(args)
results[:rate] = x.to_s.to_f
end
+ opts.on('-p', '--port number', _("Port to start the web server on; default is 4000")) do |x|
+ results[:port] = x.to_i
+ end
+
opts.separator ""
opts.separator _("Common options:")
@@ -155,7 +160,7 @@ def run(args)
@log = Logger.new('/tmp/yikes.log')
end
- start_web_service_async
+ start_web_service_async results[:port] || 4000
begin
logger.info "We're daemonized!"
@@ -183,15 +188,20 @@ def should_daemonize?
def get_logger; @log; end
- def start_web_service_async
+ def start_web_service_async(port = 4000)
Thread.new do
- Ramaze.start :adaptor => :webrick, :port => 4000
+ # The :force is there because otherwise, Ramaze cleverly decides that if
+ # we're in a spec file, we shouldn't actually start the web server
+ Ramaze.start :adaptor => :webrick, :port => port, :force => true
end
+ @port = port
end
def self.url_base
- #"http://#{Platform.hostname}.local:4000"
- "http://localhost:4000"
+ # FIXME: Something weird is going wrong with Bonjour DNS resolution
+ # when "hostname.local" == localhost
+ #"http://#{Platform.hostname}.local:#{port}"
+ "http://localhost:#{@port}"
end
end
View
@@ -2,8 +2,9 @@
require 'helper'
require 'lib/main'
+require 'lib/controllers'
require 'stringio'
-
+require 'net/http'
def hook_stdio(in_str = "")
# Hook stdio for the call
@@ -53,4 +54,15 @@ def hook_stdio(in_str = "")
o.string.index("library").should >= 0
o.string.index("target").should >= 0
end
+
+ it "should be able to spin up the Ramaze server" do
+ Yikes.instance.start_web_service_async 4503
+ Kernel.sleep 2
+
+ # This test isn't very thorough, it's more of a smoke test to make sure
+ # /public and /views aren't hosed
+ response = Net::HTTP.get URI.parse('http://localhost:4503')
+ response.include?('Yikes!').should == true
+ response.include?(Yikes.url_base).should == true
+ end
end

0 comments on commit e574916

Please sign in to comment.