diff options
author | Rick Bradley <rick@rickbradley.com> | 2007-10-16 11:13:17 -0500 |
---|---|---|
committer | Rick Bradley <rick@rickbradley.com> | 2007-10-16 11:13:17 -0500 |
commit | b8c877c121f6b376cd44b13cb90d69c41d0fb004 (patch) | |
tree | 703a7a66f7d54618fb001e5be6b003dcc0900796 /spec | |
parent | 3c370b3570d39c18799085793e083898cda72e68 (diff) | |
download | puppet-b8c877c121f6b376cd44b13cb90d69c41d0fb004.tar.gz puppet-b8c877c121f6b376cd44b13cb90d69c41d0fb004.tar.xz puppet-b8c877c121f6b376cd44b13cb90d69c41d0fb004.zip |
Registration now built for {webrick,mongrel} REST handlers.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/network/http/mongrel.rb | 6 | ||||
-rw-r--r-- | spec/unit/network/http/mongrel/rest.rb | 24 | ||||
-rw-r--r-- | spec/unit/network/http/webrick.rb | 2 | ||||
-rw-r--r-- | spec/unit/network/http/webrick/rest.rb | 24 |
4 files changed, 43 insertions, 13 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb index 161080109..bde16fee3 100644 --- a/spec/unit/network/http/mongrel.rb +++ b/spec/unit/network/http/mongrel.rb @@ -17,6 +17,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do @server = Puppet::Network::HTTP::Mongrel.new @mock_mongrel = mock('mongrel') @mock_mongrel.stubs(:run) + @mock_mongrel.stubs(:register) Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel) @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] } end @@ -53,9 +54,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do end it "should be listening" do - mock_mongrel = mock('mongrel httpserver') - mock_mongrel.expects(:run) - Mongrel::HttpServer.expects(:new).returns(mock_mongrel) + Mongrel::HttpServer.expects(:new).returns(@mock_mongrel) @server.listen(@listen_params) @server.should be_listening end @@ -94,6 +93,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do before do @mock_mongrel = mock('mongrel httpserver') @mock_mongrel.stubs(:run) + @mock_mongrel.stubs(:register) Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel) @server = Puppet::Network::HTTP::Mongrel.new @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] } diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb index 46a82183b..49562e866 100644 --- a/spec/unit/network/http/mongrel/rest.rb +++ b/spec/unit/network/http/mongrel/rest.rb @@ -9,6 +9,9 @@ require 'puppet/network/http' describe Puppet::Network::HTTP::MongrelREST, "when initializing" do before do @mock_mongrel = mock('Mongrel server') + @mock_mongrel.stubs(:register) + @mock_model = mock('indirected model') + Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model) @params = { :server => @mock_mongrel, :handler => :foo } end @@ -21,17 +24,28 @@ describe Puppet::Network::HTTP::MongrelREST, "when initializing" do end it "should look up the indirection model from the indirection name" do - mock_model = mock('indirected model') - Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model) + Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(@mock_model) Puppet::Network::HTTP::MongrelREST.new(@params) end - it "should fail if a handler is not indirected" do + it "should fail if the indirection is not known" do Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil) Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params) }.should raise_error(ArgumentError) end - - it "should register a listener for each indirection with the provided Mongrel server" + + it "should register itself with the mongrel server for the singular HTTP methods" do + @mock_mongrel.expects(:register).with do |*args| + args.first == '/foo' and args.last.is_a? Puppet::Network::HTTP::MongrelREST + end + Puppet::Network::HTTP::MongrelREST.new(@params) + end + + it "should register itself with the mongrel server for the plural GET method" do + @mock_mongrel.expects(:register).with do |*args| + args.first == '/foos' and args.last.is_a? Puppet::Network::HTTP::MongrelREST + end + Puppet::Network::HTTP::MongrelREST.new(@params) + end end describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index 81b2a0fa9..9ba04f164 100644 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -17,6 +17,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do Puppet.stubs(:start) Puppet.stubs(:newservice) @mock_webrick = mock('webrick') + @mock_webrick.stubs(:mount) WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] } @@ -94,6 +95,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do Puppet.stubs(:start) Puppet.stubs(:newservice) @mock_webrick = mock('webrick') + @mock_webrick.stubs(:mount) WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick) @server = Puppet::Network::HTTP::WEBrick.new @server.stubs(:shutdown) diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb index 5a1b53da0..70c50bf39 100644 --- a/spec/unit/network/http/webrick/rest.rb +++ b/spec/unit/network/http/webrick/rest.rb @@ -9,6 +9,9 @@ require 'puppet/network/http' describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do before do @mock_webrick = mock('WEBrick server') + @mock_webrick.stubs(:mount) + @mock_model = mock('indirected model') + Puppet::Indirector::Indirection.stubs(:model).returns(@mock_model) @params = { :server => @mock_webrick, :handler => :foo } end @@ -21,17 +24,28 @@ describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do end it "should look up the indirection model from the indirection name" do - mock_model = mock('indirected model') - Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model) + Puppet::Indirector::Indirection.expects(:model).returns(@mock_model) Puppet::Network::HTTP::WEBrickREST.new(@params) end - it "should fail if a handler is not indirected" do - Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil) + it "should fail if the indirection is not known" do + Puppet::Indirector::Indirection.expects(:model).returns(nil) Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params) }.should raise_error(ArgumentError) end - it "should register a listener for each indirection with the provided WEBrick server" + it "should register itself with the WEBrick server for the singular HTTP methods" do + @mock_webrick.expects(:mount).with do |*args| + args.first == '/foo' and args.last.is_a?(Puppet::Network::HTTP::WEBrickREST) + end + Puppet::Network::HTTP::WEBrickREST.new(@params) + end + + it "should register itself with the WEBrick server for the plural GET method" do + @mock_webrick.expects(:mount).with do |*args| + args.first == '/foos' and args.last.is_a?(Puppet::Network::HTTP::WEBrickREST) + end + Puppet::Network::HTTP::WEBrickREST.new(@params) + end end describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do |