Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
lib/puppet/provider/package/gem.rb | 26 +++++++++++++++++----
spec/unit/ral/provider/package/gem.rb | 39 +++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 5 deletions(-)
create mode 100644 spec/unit/ral/provider/package/gem.rb
diff --git a/lib/puppet/provider/package/gem.rb
b/lib/puppet/provider/package/gem.rb
index bb09bc5..277fc68 100755
--- a/lib/puppet/provider/package/gem.rb
+++ b/lib/puppet/provider/package/gem.rb
@@ -1,9 +1,12 @@
require 'puppet/provider/package'
+require 'uri'
# Ruby gems support.
Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package
do
- desc "Ruby Gem support. By default uses remote gems, but you can specify
- the path to a local gem via ``source``."
+ desc "Ruby Gem support. If a URL is passed via ``source``, then that URL
is used as the
+ remote gem repository; if a source is present but is not a valid URL,
it will be
+ interpreted as the path to a local gem file. If source is not
present at all,
+ the gem will be installed from the default gem repositories."
has_feature :versionable
@@ -65,7 +68,7 @@ Puppet::Type.type(:package).provide :gem, :parent =>
Puppet::Provider::Package d
end
def install(useversion = true)
- command = ["install"]
+ command = [command(:gemcmd), "install"]
if (! @resource.should(:ensure).is_a? Symbol) and useversion
command << "-v" << @resource.should(:ensure)
end
@@ -73,12 +76,25 @@ Puppet::Type.type(:package).provide :gem, :parent =>
Puppet::Provider::Package d
command << "--include-dependencies"
if source = @resource[:source]
- command << source
+ scheme = URI.parse(blah).scheme rescue nil # the URI scheme if
there is one, nil otherwise
+
+ if scheme.nil?
+ # no URI scheme => interpret the source as a local file
+ command << source
+ elsif scheme.downcase == "file"
+ command << source.path
+ elsif scheme.downcase == "puppet"
+ # we don't support puppet:// URLs (yet)
+ raise Puppet::Error.new("puppet:// URLs are not supported as gem
sources")
+ else
+ # interpret it as a gem repository
+ command << "--source" << "#{source}" << @resource[:name]
+ end
else
command << @resource[:name]
end
- output = gemcmd(*command)
+ output = execute(command)
# Apparently some stupid gem versions don't exit non-0 on failure
if output.include?("ERROR")
self.fail "Could not install: %s" % output.chomp
diff --git a/spec/unit/ral/provider/package/gem.rb
b/spec/unit/ral/provider/package/gem.rb
new file mode 100644
index 0000000..fcd8bf4
--- /dev/null
+++ b/spec/unit/ral/provider/package/gem.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+require 'puppet/provider/package/gem'
+
+provider_class = Puppet::Type.type(:package).provider(:gem)
+
+describe provider_class do
+ it "should have an install method" do
+ @provider = provider_class.new
+ @provider.should respond_to(:install)
+ end
+
+ describe "when installing" do
+ before do
+ # Create a mock resource
+ @resource = mock 'resource'
+
+ # A catch all; no parameters set
+ @resource.stubs(:[]).returns nil
+
+ # We have to set a name, though
+ @resource.stubs(:[]).with(:name).returns "myresource"
+
+ # BTW, you get odd error messages from rspec if you forget to mock
"should" here...
+ @resource.stubs(:should).with(:ensure).returns :installed
+
+ @provider = provider_class.new
+ @provider.stubs(:resource).returns @resource
+ # Create a provider that uses the mock
+# @provider = provider_class.new(@resource)
+ end
+
+ it "should execute the gem command with 'install', dependencies, and the
package name" do
+ @provider.expects(:execute).with(provider_class.command(:gemcmd),
'install', "--include-dependences", "myresource")
+ @provider.install
+ end
+ end
+end
--
1.5.3.7
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---