summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/webrick.rb8
-rw-r--r--spec/unit/network/http/webrick.rb17
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index c22bce938..b74bf441e 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -1,7 +1,7 @@
require 'webrick'
require 'webrick/https'
-class Puppet::Network::HTTP::WEBrick < WEBrick::HTTPServer
+class Puppet::Network::HTTP::WEBrick
def initialize(args = {})
@listening = false
end
@@ -12,8 +12,12 @@ class Puppet::Network::HTTP::WEBrick < WEBrick::HTTPServer
raise ArgumentError, ":port must be specified." unless args[:port]
raise "WEBrick server is already listening" if listening?
- # TODO / FIXME: this should be moved out of the wacky Puppet global namespace!
+ @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port])
+
+ # TODO / FIXME is this really necessary? -- or can we do it in both mongrel and webrick?
+ Puppet.newservice(@server)
Puppet.start
+
@listening = true
end
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 9ab97e831..804be4c33 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -14,9 +14,12 @@ end
describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
before do
+ Puppet.stubs(:start)
+ Puppet.stubs(:newservice)
+ @mock_webrick = mock('webrick')
+ WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
@listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
- Puppet.stubs(:start)
end
it "should fail if already listening" do
@@ -41,7 +44,12 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@server.listen(@listen_params)
end
- it "should tell webrick to listen on the specified address and port"
+ it "should tell webrick to listen on the specified address and port" do
+ WEBrick::HTTPServer.expects(:new).with {|args|
+ args[:Port] == 31337 and args[:BindAddress] == "127.0.0.1"
+ }.returns(@mock_webrick)
+ @server.listen(@listen_params)
+ end
it "should be listening" do
@server.listen(@listen_params)
@@ -54,10 +62,13 @@ end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
before do
+ Puppet.stubs(:start)
+ Puppet.stubs(:newservice)
+ @mock_webrick = mock('webrick')
+ WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
@server.stubs(:shutdown)
@listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
- Puppet.stubs(:start).returns(true)
end
it "should fail unless listening" do