Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enable passing custom options to rack handler

  • Loading branch information...
commit b73b4b68230c3f619e6aa0b576af516c37b741f3 1 parent 4df8b4c
@wojtekmach wojtekmach authored
Showing with 15 additions and 5 deletions.
  1. +5 −5 lib/shamrock/service.rb
  2. +10 −0 spec/shamrock/service_spec.rb
View
10 lib/shamrock/service.rb
@@ -11,18 +11,18 @@ class Service
def initialize(rack_app, options = {})
@rack_app = rack_app
- options = DEFAULT_OPTIONS.merge(options)
+ @options = DEFAULT_OPTIONS.merge(options)
- @handler = options[:handler]
+ @handler = @options.delete(:handler)
- @port = options[:port] || find_available_port
+ @port = @options.delete(:port) || find_available_port
@url = "http://localhost:#{port}"
- @monitor = options[:monitor].new(Http.new(url))
+ @monitor = @options.delete(:monitor).new(Http.new(url))
end
def start
@thread = Thread.new do
- @handler.run(@rack_app, Port: port)
+ @handler.run(@rack_app, @options.merge(Port: port))
end
@monitor.wait_until_ready
View
10 spec/shamrock/service_spec.rb
@@ -28,6 +28,16 @@
service.start
end
+ it "should start the server with custom handler options" do
+ monitor = mock('monitor', wait_until_ready: true)
+ monitor_class = mock('monitor class', new: monitor)
+
+ handler = mock('handler')
+ service = Shamrock::Service.new(@rack_app, handler: handler, monitor: monitor_class, foo: 'bar')
+ handler.should_receive(:run).with(@rack_app, Port: service.port, foo: 'bar')
+ service.start
+ end
+
it "should wait for the server to become available" do
monitor = mock('monitor')
monitor_class = mock('monitor class', new: monitor)
Please sign in to comment.
Something went wrong with that request. Please try again.