summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/mongrel/rest.rb2
-rw-r--r--lib/puppet/rails/database/001_add_created_at_to_all_tables.rb28
-rwxr-xr-xspec/integration/indirector/rest.rb814
-rwxr-xr-xspec/integration/network/server/mongrel.rb72
-rwxr-xr-xspec/integration/network/server/webrick.rb76
-rw-r--r--spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb46
-rw-r--r--spec/spec_helper.rb2
-rwxr-xr-xspec/unit/indirector/module_files.rb36
-rwxr-xr-xspec/unit/network/http/webrick.rb30
9 files changed, 553 insertions, 553 deletions
diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb
index d1257d5cb..520ad67f0 100644
--- a/lib/puppet/network/http/mongrel/rest.rb
+++ b/lib/puppet/network/http/mongrel/rest.rb
@@ -2,7 +2,7 @@ require 'puppet/network/http/handler'
class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler
- include Puppet::Network::HTTP::Handler
+ include Puppet::Network::HTTP::Handler
def initialize(args={})
super()
diff --git a/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
index 71ee6aeed..d1035b0db 100644
--- a/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
+++ b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
@@ -1,17 +1,17 @@
class AddCreatedAtToAllTables < ActiveRecord::Migration
- def self.up
- ActiveRecord::Base.connection.tables.each do |t|
- unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
- add_column t.to_s, :created_at, :datetime
- end
- end
- end
+ def self.up
+ ActiveRecord::Base.connection.tables.each do |t|
+ unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
+ add_column t.to_s, :created_at, :datetime
+ end
+ end
+ end
- def self.down
- ActiveRecord::Base.connection.tables.each do |t|
- unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
- remove_column t.to_s, :created_at
- end
- end
- end
+ def self.down
+ ActiveRecord::Base.connection.tables.each do |t|
+ unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
+ remove_column t.to_s, :created_at
+ end
+ end
+ end
end
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index b5e74e609..c1cefd4ca 100755
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -7,22 +7,22 @@ require 'puppet/indirector/rest'
# a fake class that will be indirected via REST
class Puppet::TestIndirectedFoo
- extend Puppet::Indirector
- indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
-
- attr_reader :value
-
- def initialize(value = 0)
- @value = value
- end
-
- def self.from_yaml(yaml)
- YAML.load(yaml)
- end
-
- def name
- "bob"
- end
+ extend Puppet::Indirector
+ indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
+
+ attr_reader :value
+
+ def initialize(value = 0)
+ @value = value
+ end
+
+ def self.from_yaml(yaml)
+ YAML.load(yaml)
+ end
+
+ def name
+ "bob"
+ end
end
# empty Terminus class -- this would normally have to be in a directory findable by the autoloader, but we short-circuit that below
@@ -31,432 +31,432 @@ end
describe Puppet::Indirector::REST do
- describe "when using webrick" do
- before :each do
- Puppet[:servertype] = 'webrick'
- @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :test_indirected_foo ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
+ describe "when using webrick" do
+ before :each do
+ Puppet[:servertype] = 'webrick'
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :test_indirected_foo ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
- # the autoloader was clearly not written test-first. We subvert the integration test to get around its bullshit.
- Puppet::Indirector::Terminus.stubs(:terminus_class).returns(Puppet::TestIndirectedFoo::Rest)
- Puppet::TestIndirectedFoo.indirection.stubs(:terminus_class).returns :rest
+ # the autoloader was clearly not written test-first. We subvert the integration test to get around its bullshit.
+ Puppet::Indirector::Terminus.stubs(:terminus_class).returns(Puppet::TestIndirectedFoo::Rest)
+ Puppet::TestIndirectedFoo.indirection.stubs(:terminus_class).returns :rest
- # Stub the connection information.
- Puppet::TestIndirectedFoo.indirection.terminus(:rest).stubs(:rest_connection_details).returns(:host => "localhost", :port => 34343)
- end
-
- describe "when finding a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @model_instance = Puppet::TestIndirectedFoo.new(23)
- @mock_model = stub('faked model', :find => @model_instance)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- Puppet::TestIndirectedFoo.find('bar')
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
- end
-
- it 'should set an expiration on model instance' do
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
+ # Stub the connection information.
+ Puppet::TestIndirectedFoo.indirection.terminus(:rest).stubs(:rest_connection_details).returns(:host => "localhost", :port => 34343)
end
- end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :find => nil)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
+ describe "when finding a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @model_instance = Puppet::TestIndirectedFoo.new(23)
+ @mock_model = stub('faked model', :find => @model_instance)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ Puppet::TestIndirectedFoo.find('bar')
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
+ end
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
- end
- end
- end
-
- describe "when searching for model instances over REST" do
- describe "when matching model instances can be found" do
- before :each do
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
- @mock_model = stub('faked model', :search => @model_instances)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
- end
-
- it 'should return all matching results' do
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
- end
-
- it 'should return model instances' do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.class.should == Puppet::TestIndirectedFoo
- end
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value)
- end
-
- it 'should set a version timestamp on model instances' do
- pending("Luke looking at why this version magic might not be working") do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.version.should_not be_nil
+ it 'should return an instance of the model class' do
+ Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
+ end
+
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :find => nil)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ end
end
- end
end
- end
+
+ describe "when searching for model instances over REST" do
+ describe "when matching model instances can be found" do
+ before :each do
+ @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+ @mock_model = stub('faked model', :search => @model_instances)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
+ end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :find => nil)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
+ it 'should return all matching results' do
+ Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
+ end
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ it 'should return model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.class.should == Puppet::TestIndirectedFoo
+ end
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value)
+ end
+
+ it 'should set a version timestamp on model instances' do
+ pending("Luke looking at why this version magic might not be working") do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.version.should_not be_nil
+ end
+ end
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :find => nil)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ end
+ end
end
- end
- end
- describe "when destroying a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :destroy => true)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
- end
-
- it 'should return success' do
- Puppet::TestIndirectedFoo.destroy('bar').should == true
- end
- end
+ describe "when destroying a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :destroy => true)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
+ end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :destroy => false)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return failure" do
- Puppet::TestIndirectedFoo.destroy('bar').should == false
+ it 'should return success' do
+ Puppet::TestIndirectedFoo.destroy('bar').should == true
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :destroy => false)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return failure" do
+ Puppet::TestIndirectedFoo.destroy('bar').should == false
+ end
+ end
+
+ describe "when an exception is encountered in destroying a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:destroy).raises(RuntimeError)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError)
+ end
+ end
end
- end
+
+ describe "when saving a model instance over REST" do
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model = stub('faked model', :from_yaml => @instance)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
+ end
+
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
- describe "when an exception is encountered in destroying a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:destroy).raises(RuntimeError)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError)
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(RuntimeError)
+ end
+ end
end
- end
- end
- describe "when saving a model instance over REST" do
- before :each do
- @instance = Puppet::TestIndirectedFoo.new(42)
- @mock_model = stub('faked model', :from_yaml => @instance)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
- end
-
- describe "when a successful save can be performed" do
- before :each do
- end
-
- it "should not fail" do
- lambda { @instance.save }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- @instance.save.class.should == Puppet::TestIndirectedFoo
- end
-
- it 'should return a matching instance of the model class' do
- @instance.save.value.should == @instance.value
- end
- end
-
- describe "when a save cannot be completed" do
- before :each do
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
- end
-
- it "should return failure" do
- @instance.save.should == false
- end
- end
-
- describe "when an exception is encountered in performing a save" do
- before :each do
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ after :each do
+ @server.unlisten
end
-
- it "should raise an exception" do
- lambda { @instance.save }.should raise_error(RuntimeError)
- end
- end
- end
-
- after :each do
- @server.unlisten
end
- end
- describe "when using mongrel" do
- confine "Mongrel is not available" => Puppet.features.mongrel?
-
- before :each do
- Puppet[:servertype] = 'mongrel'
- @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :test_indirected_foo ] }
- @server = Puppet::Network::Server.new(@params)
- @server.listen
+ describe "when using mongrel" do
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
+ before :each do
+ Puppet[:servertype] = 'mongrel'
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :test_indirected_foo ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
- # the autoloader was clearly not written test-first. We subvert the integration test to get around its bullshit.
- Puppet::Indirector::Terminus.stubs(:terminus_class).returns(Puppet::TestIndirectedFoo::Rest)
- Puppet::TestIndirectedFoo.indirection.stubs(:terminus_class).returns :rest
+ # the autoloader was clearly not written test-first. We subvert the integration test to get around its bullshit.
+ Puppet::Indirector::Terminus.stubs(:terminus_class).returns(Puppet::TestIndirectedFoo::Rest)
+ Puppet::TestIndirectedFoo.indirection.stubs(:terminus_class).returns :rest
- # Stub the connection information.
- Puppet::TestIndirectedFoo.indirection.terminus(:rest).stubs(:rest_connection_details).returns(:host => "localhost", :port => 34343)
- end
-
- describe "when finding a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @model_instance = Puppet::TestIndirectedFoo.new(23)
- @mock_model = stub('faked model', :find => @model_instance)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
+ # Stub the connection information.
+ Puppet::TestIndirectedFoo.indirection.terminus(:rest).stubs(:rest_connection_details).returns(:host => "localhost", :port => 34343)
end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
- end
-
- it 'should set an expiration on model instance' do
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
- end
- end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :find => nil)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
+ describe "when finding a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @model_instance = Puppet::TestIndirectedFoo.new(23)
+ @mock_model = stub('faked model', :find => @model_instance)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
+ end
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ it 'should return an instance of the model class' do
+ Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
+ end
+
+ it 'should set an expiration on model instance' do
+ Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :find => nil)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ end
+ end
end
- end
- end
- describe "when searching for model instances over REST" do
- describe "when matching model instances can be found" do
- before :each do
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
- @mock_model = stub('faked model', :search => @model_instances)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
- end
-
- it 'should return all matching results' do
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
- end
-
- it 'should return model instances' do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.class.should == Puppet::TestIndirectedFoo
- end
- end
-
- it 'should return the instance of the model class associated with the provided lookup key' do
- Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value)
- end
-
- it 'should set an expiration on model instances' do
- Puppet::TestIndirectedFoo.search('bar').each do |result|
- result.expiration.should_not be_nil
- end
- end
- end
+ describe "when searching for model instances over REST" do
+ describe "when matching model instances can be found" do
+ before :each do
+ @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+ @mock_model = stub('faked model', :search => @model_instances)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
+ end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :find => nil)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return nil" do
- Puppet::TestIndirectedFoo.find('bar').should be_nil
- end
- end
+ it 'should return all matching results' do
+ Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
+ end
- describe "when an exception is encountered in looking up a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:find).raises(RuntimeError)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ it 'should return model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.class.should == Puppet::TestIndirectedFoo
+ end
+ end
+
+ it 'should return the instance of the model class associated with the provided lookup key' do
+ Puppet::TestIndirectedFoo.search('bar').collect(&:value).should == @model_instances.collect(&:value)
+ end
+
+ it 'should set an expiration on model instances' do
+ Puppet::TestIndirectedFoo.search('bar').each do |result|
+ result.expiration.should_not be_nil
+ end
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :find => nil)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return nil" do
+ Puppet::TestIndirectedFoo.find('bar').should be_nil
+ end
+ end
+
+ describe "when an exception is encountered in looking up a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:find).raises(RuntimeError)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(RuntimeError)
+ end
+ end
end
- end
- end
- describe "when destroying a model instance over REST" do
- describe "when a matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :destroy => true)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should not fail" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
- end
-
- it 'should return success' do
- Puppet::TestIndirectedFoo.destroy('bar').should == true
- end
- end
+ describe "when destroying a model instance over REST" do
+ describe "when a matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :destroy => true)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should not fail" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
+ end
- describe "when no matching model instance can be found" do
- before :each do
- @mock_model = stub('faked model', :destroy => false)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should return failure" do
- Puppet::TestIndirectedFoo.destroy('bar').should == false
+ it 'should return success' do
+ Puppet::TestIndirectedFoo.destroy('bar').should == true
+ end
+ end
+
+ describe "when no matching model instance can be found" do
+ before :each do
+ @mock_model = stub('faked model', :destroy => false)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should return failure" do
+ Puppet::TestIndirectedFoo.destroy('bar').should == false
+ end
+ end
+
+ describe "when an exception is encountered in destroying a model instance" do
+ before :each do
+ @mock_model = stub('faked model')
+ @mock_model.stubs(:destroy).raises(RuntimeError)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ it "should raise an exception" do
+ lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError)
+ end
+ end
end
- end
+
+ describe "when saving a model instance over REST" do
+ before :each do
+ @instance = Puppet::TestIndirectedFoo.new(42)
+ @mock_model = stub('faked model', :from_yaml => @instance)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
+ end
+
+ describe "when a successful save can be performed" do
+ before :each do
+ end
+
+ it "should not fail" do
+ lambda { @instance.save }.should_not raise_error
+ end
- describe "when an exception is encountered in destroying a model instance" do
- before :each do
- @mock_model = stub('faked model')
- @mock_model.stubs(:destroy).raises(RuntimeError)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- end
-
- it "should raise an exception" do
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError)
+ it 'should return an instance of the model class' do
+ @instance.save.class.should == Puppet::TestIndirectedFoo
+ end
+
+ it 'should return a matching instance of the model class' do
+ @instance.save.value.should == @instance.value
+ end
+ end
+
+ describe "when a save cannot be completed" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
+ end
+
+ it "should return failure" do
+ @instance.save.should == false
+ end
+ end
+
+ describe "when an exception is encountered in performing a save" do
+ before :each do
+ Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
+ end
+
+ it "should raise an exception" do
+ lambda { @instance.save }.should raise_error(RuntimeError)
+ end
+ end
end
- end
- end
- describe "when saving a model instance over REST" do
- before :each do
- @instance = Puppet::TestIndirectedFoo.new(42)
- @mock_model = stub('faked model', :from_yaml => @instance)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model)
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
- end
-
- describe "when a successful save can be performed" do
- before :each do
- end
-
- it "should not fail" do
- lambda { @instance.save }.should_not raise_error
- end
-
- it 'should return an instance of the model class' do
- @instance.save.class.should == Puppet::TestIndirectedFoo
- end
-
- it 'should return a matching instance of the model class' do
- @instance.save.value.should == @instance.value
+ after :each do
+ @server.unlisten
end
- end
-
- describe "when a save cannot be completed" do
- before :each do
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
- end
-
- it "should return failure" do
- @instance.save.should == false
- end
- end
-
- describe "when an exception is encountered in performing a save" do
- before :each do
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
- end
-
- it "should raise an exception" do
- lambda { @instance.save }.should raise_error(RuntimeError)
- end
- end
- end
-
- after :each do
- @server.unlisten
end
- end
end
diff --git a/spec/integration/network/server/mongrel.rb b/spec/integration/network/server/mongrel.rb
index 0603b1133..180fdf7ad 100755
--- a/spec/integration/network/server/mongrel.rb
+++ b/spec/integration/network/server/mongrel.rb
@@ -5,44 +5,44 @@ require 'puppet/network/server'
require 'socket'
describe Puppet::Network::Server do
- describe "when using mongrel" do
- confine "Mongrel is not available" => Puppet.features.mongrel?
-
- before :each do
- Puppet[:servertype] = 'mongrel'
- @params = { :address => "127.0.0.1", :port => 34346, :handlers => [ :node ] }
- @server = Puppet::Network::Server.new(@params)
- end
+ describe "when using mongrel" do
+ confine "Mongrel is not available" => Puppet.features.mongrel?
+
+ before :each do
+ Puppet[:servertype] = 'mongrel'
+ @params = { :address => "127.0.0.1", :port => 34346, :handlers => [ :node ] }
+ @server = Puppet::Network::Server.new(@params)
+ end
- describe "before listening" do
- it "should not be reachable at the specified address and port" do
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
- end
- end
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
- describe "when listening" do
- it "should be reachable on the specified address and port" do
- @server.listen
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should_not raise_error
- end
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should_not raise_error
+ end
- it "should not allow multiple servers to listen on the same address and port" do
- @server.listen
- @server2 = Puppet::Network::Server.new(@params)
- lambda { @server2.listen }.should raise_error
- end
- end
-
- describe "after unlistening" do
- it "should not be reachable on the port and address assigned" do
- @server.listen
- @server.unlisten
- lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
- end
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params)
+ lambda { @server2.listen }.should raise_error
+ end
+ end
+
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34346) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
+
+ after :each do
+ @server.unlisten if @server.listening?
+ end
end
-
- after :each do
- @server.unlisten if @server.listening?
- end
- end
end
diff --git a/spec/integration/network/server/webrick.rb b/spec/integration/network/server/webrick.rb
index f20ce0860..41714271f 100755
--- a/spec/integration/network/server/webrick.rb
+++ b/spec/integration/network/server/webrick.rb
@@ -5,44 +5,44 @@ require 'puppet/network/server'
require 'socket'
describe Puppet::Network::Server do
- describe "when using webrick" do
- before :each do
- Puppet[:servertype] = 'webrick'
- @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :node ] }
- end
-
- describe "before listening" do
- it "should not be reachable at the specified address and port" do
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error
- end
- end
-
- describe "when listening" do
- it "should be reachable on the specified address and port" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should_not raise_error
- end
+ describe "when using webrick" do
+ before :each do
+ Puppet[:servertype] = 'webrick'
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :node ] }
+ end
+
+ describe "before listening" do
+ it "should not be reachable at the specified address and port" do
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error
+ end
+ end
+
+ describe "when listening" do
+ it "should be reachable on the specified address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should_not raise_error
+ end
+
+ it "should not allow multiple servers to listen on the same address and port" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server2 = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ lambda { @server2.listen }.should raise_error
+ end
- it "should not allow multiple servers to listen on the same address and port" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- @server2 = Puppet::Network::Server.new(@params.merge(:port => 34343))
- lambda { @server2.listen }.should raise_error
- end
-
- after :each do
- @server.unlisten if @server.listening?
- end
- end
-
- describe "after unlistening" do
- it "should not be reachable on the port and address assigned" do
- @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
- @server.listen
- @server.unlisten
- lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error(Errno::ECONNREFUSED)
- end
+ after :each do
+ @server.unlisten if @server.listening?
+ end
+ end
+
+ describe "after unlistening" do
+ it "should not be reachable on the port and address assigned" do
+ @server = Puppet::Network::Server.new(@params.merge(:port => 34343))
+ @server.listen
+ @server.unlisten
+ lambda { TCPSocket.new('127.0.0.1', 34343) }.should raise_error(Errno::ECONNREFUSED)
+ end
+ end
end
- end
end
diff --git a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb
index e2f3d4728..0b4a5abdb 100644
--- a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb
+++ b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb
@@ -1,7 +1,7 @@
dir = File.expand_path(File.dirname(__FILE__))
[ "#{dir}/../../lib", "#{dir}/../../test/lib"].each do |dir|
- fulldir = File.expand_path(dir)
- $LOAD_PATH.unshift(fulldir) unless $LOAD_PATH.include?(fulldir)
+ fulldir = File.expand_path(dir)
+ $LOAD_PATH.unshift(fulldir) unless $LOAD_PATH.include?(fulldir)
end
require 'spec'
@@ -9,35 +9,35 @@ require 'puppettest'
require 'puppettest/runnable_test'
module Spec
- module Runner
- class ExampleGroupRunner
- def run
- prepare
- success = true
- example_groups.each do |example_group|
- next unless example_group.runnable?
- success = success & example_group.run
+ module Runner
+ class ExampleGroupRunner
+ def run
+ prepare
+ success = true
+ example_groups.each do |example_group|
+ next unless example_group.runnable?
+ success = success & example_group.run
+ end
+ return success
+ ensure
+ finish
+ end
end
- return success
- ensure
- finish
- end
end
- end
end
module Spec
- module Example
- class ExampleGroup
- extend PuppetTest::RunnableTest
+ module Example
+ class ExampleGroup
+ extend PuppetTest::RunnableTest
+ end
end
- end
end
module Test
- module Unit
- class TestCase
- extend PuppetTest::RunnableTest
+ module Unit
+ class TestCase
+ extend PuppetTest::RunnableTest
+ end
end
- end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index db14b47cb..7909adca3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -23,7 +23,7 @@ require 'spec'
Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file }
Spec::Runner.configure do |config|
- config.mock_with :mocha
+ config.mock_with :mocha
# config.prepend_before :all do
# setup_mocks_for_rspec
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb
index 0f6dbb6df..f5b92e1fd 100755
--- a/spec/unit/indirector/module_files.rb
+++ b/spec/unit/indirector/module_files.rb
@@ -10,24 +10,24 @@ require 'puppet/indirector/module_files'
describe Puppet::Indirector::ModuleFiles do
- before :each do
- Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
- Puppet::Indirector::Terminus.stubs(:register_terminus_class)
- @model = mock 'model'
- @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
- Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
-
- @module_files_class = Class.new(Puppet::Indirector::ModuleFiles) do
- def self.to_s
- "Testing::Mytype"
- end
- end
-
- @module_files = @module_files_class.new
-
- @uri = "puppetmounts://host/modules/my/local/file"
- @module = Puppet::Module.new("mymod", "/module/path")
- end
+ before :each do
+ Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv"))
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @model = mock 'model'
+ @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
+ Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
+
+ @module_files_class = Class.new(Puppet::Indirector::ModuleFiles) do
+ def self.to_s
+ "Testing::Mytype"
+ end
+ end
+
+ @module_files = @module_files_class.new
+
+ @uri = "puppetmounts://host/modules/my/local/file"
+ @module = Puppet::Module.new("mymod", "/module/path")
+ end
describe Puppet::Indirector::ModuleFiles, " when finding files" do
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 05ed2f0e2..78bd39145 100755
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -82,21 +82,21 @@ end
describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a protocol" do
- it "should require a protocol" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError)
- end
-
- it "should accept a protocol" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError)
- end
-
- it "should use a WEBrick + REST class when a REST protocol is specified" do
- Puppet::Network::HTTP::WEBrick.class_for_protocol("rest").should == Puppet::Network::HTTP::WEBrickREST
- end
-
- it "should fail when an unknown protocol is specified" do
- lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("abcdefg") }.should raise_error
- end
+ it "should require a protocol" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError)
+ end
+
+ it "should accept a protocol" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("bob") }.should_not raise_error(ArgumentError)
+ end
+
+ it "should use a WEBrick + REST class when a REST protocol is specified" do
+ Puppet::Network::HTTP::WEBrick.class_for_protocol("rest").should == Puppet::Network::HTTP::WEBrickREST
+ end
+
+ it "should fail when an unknown protocol is specified" do
+ lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol("abcdefg") }.should raise_error
+ end
end
describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do