diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-15 12:04:30 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-15 12:04:30 -0500 |
| commit | ec71e05a162ec299982b90707cc16231c608997b (patch) | |
| tree | c16376f369f5ad880b17f47888c9cea33a9008bb /spec/unit | |
| parent | 31384fea2263d9ee0e65312b4a0b956436022e63 (diff) | |
| download | puppet-ec71e05a162ec299982b90707cc16231c608997b.tar.gz puppet-ec71e05a162ec299982b90707cc16231c608997b.tar.xz puppet-ec71e05a162ec299982b90707cc16231c608997b.zip | |
More unit specs for mongrel and webrick; more code to make them work, yo.
Diffstat (limited to 'spec/unit')
| -rw-r--r-- | spec/unit/network/http/mongrel.rb | 53 | ||||
| -rw-r--r-- | spec/unit/network/http/webrick.rb | 52 | ||||
| -rw-r--r-- | spec/unit/network/server.rb | 24 |
3 files changed, 106 insertions, 23 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb new file mode 100644 index 000000000..3e40efe79 --- /dev/null +++ b/spec/unit/network/http/mongrel.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby +# +# Created by Rick Bradley on 2007-10-15. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'puppet/network/http' + +describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do + before do + @server = Puppet::Network::HTTP::Mongrel.new + end + + it "should fail if already listening" do + @server.listen(:foo => :bar) + Proc.new { @server.listen(:foo => :bar) }.should raise_error(RuntimeError) + end + + it "should require at least one handler" do + Proc.new { @server.listen }.should raise_error(ArgumentError) + end + + it "should order a mongrel server to start" do + mock_mongrel = mock('mongrel httpserver') + mock_mongrel.expects(:run) + Mongrel::HttpServer.expects(:new).returns(mock_mongrel) + @server.listen(:foo => :bar) + end + + it "should instantiate a specific handler (mongrel+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)" + it "should mount handlers on a mongrel path" + it "should be able to specify the address on which mongrel will listen" + it "should be able to specify the port on which mongrel will listen" +end + +describe Puppet::Network::HTTP::WEBRick, "when turning off listening" do + before do + @mock_mongrel = mock('mongrel httpserver') + @mock_mongrel.stubs(:run) + Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel) + @server = Puppet::Network::HTTP::Mongrel.new + end + + it "should fail unless listening" do + Proc.new { @server.unlisten }.should raise_error(RuntimeError) + end + + it "should order mongrel server to stop" do + @server.listen(:foo => :bar) + @mock_mongrel.expects(:graceful_shutdown) + @server.unlisten + end +end diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb new file mode 100644 index 000000000..d162288fc --- /dev/null +++ b/spec/unit/network/http/webrick.rb @@ -0,0 +1,52 @@ +#!/usr/bin/env ruby +# +# Created by Rick Bradley on 2007-10-15. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'puppet/network/http' + +describe Puppet::Network::HTTP::WEBRick, "when turning on listening" do + before do + @server = Puppet::Network::HTTP::WEBRick.new + end + + it "should fail if already listening" do + Puppet.stubs(:start) + @server.listen(:foo => :bar) + Proc.new { @server.listen(:foo => :bar) }.should raise_error(RuntimeError) + end + + it "should require at least one handler" do + Proc.new { @server.listen }.should raise_error(ArgumentError) + end + + it "should order a webrick server to start" do + Puppet.expects(:start) + @server.listen(:foo => :bar) + end + + it "should instantiate a specific handler (webrick+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)" + it "should mount handlers on a webrick path" + + it "should be able to specify the address on which webrick will listen" + it "should be able to specify the port on which webrick will listen" +end + +describe Puppet::Network::HTTP::WEBRick, "when turning off listening" do + before do + @server = Puppet::Network::HTTP::WEBRick.new + end + + it "should fail unless listening" do + Proc.new { @server.unlisten }.should raise_error(RuntimeError) + end + + it "should order webrick server to stop" do + Puppet.stubs(:start).returns(true) + @server.should respond_to(:shutdown) + @server.expects(:shutdown) + @server.listen(:foo => :bar) + @server.unlisten + end +end diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb index b2994c6f9..f5d5e25d5 100644 --- a/spec/unit/network/server.rb +++ b/spec/unit/network/server.rb @@ -4,10 +4,8 @@ # Copyright (c) 2007. All rights reserved. require File.dirname(__FILE__) + '/../../spec_helper' - require 'puppet/network/server' - describe Puppet::Network::Server, "when initializing" do before do @mock_http_server_class = mock('http server class') @@ -212,7 +210,7 @@ describe Puppet::Network::Server, "when listening is being turned off" do @server.stubs(:http_server).returns(@mock_http_server) @server.listen end - + it "should cause the HTTP server to stop listening when listening is turned off" do @mock_http_server.expects(:unlisten) @server.unlisten @@ -224,26 +222,6 @@ describe Puppet::Network::Server, "when listening is being turned off" do end end -describe Class.new, "Puppet::Network::HTTP::Webrick (webrick http server class)" do - it "should allow listening" - it "should get a set of handlers when listening" - it "should allow unlistening" - it "should instantiate a specific handler (webrick+rest, e.g.) for each handler when listening, for each protocol being served (xmlrpc, rest, etc.)" - it "should mount each handler with the appropriate webrick path when listening" - it "should start webrick when listening" - it "should stop webrick when unlistening" -end - -describe Class.new, "Puppet::Network::HTTP::Mongrel (mongrel http server class)" do - it "should allow listening" - it "should get a set of handlers when listening" - it "should allow unlistening" - it "should instantiate a specific handler (mongrel+rest, e.g.) for each handler when listening, for each protocol being served (xmlrpc, rest, etc.)" - it "should mount each handler with the appropriate mongrel path when listening" - it "should start mongrel when listening" - it "should stop mongrel when unlistening" -end - describe Class.new, "Puppet::Network::Handler::*::* (handler class (e.g., webrick+rest or mongrel+xmlrpc))" do it "should be able to unserialize a request from the given httpserver answering for the given protocol handler, to be used by a controller" it "should be able to serialize a result from a controller for return by the given httpserver responding with the given protocol" |
