diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/provider/package | |
parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'spec/unit/provider/package')
-rwxr-xr-x | spec/unit/provider/package/aix_spec.rb | 90 | ||||
-rwxr-xr-x | spec/unit/provider/package/apt_spec.rb | 188 | ||||
-rwxr-xr-x | spec/unit/provider/package/dpkg_spec.rb | 326 | ||||
-rw-r--r-- | spec/unit/provider/package/gem_spec.rb | 134 | ||||
-rw-r--r-- | spec/unit/provider/package/hpux_spec.rb | 82 | ||||
-rwxr-xr-x | spec/unit/provider/package/nim_spec.rb | 62 | ||||
-rw-r--r-- | spec/unit/provider/package/pkg_spec.rb | 110 | ||||
-rwxr-xr-x | spec/unit/provider/package/pkgdmg_spec.rb | 126 | ||||
-rw-r--r-- | spec/unit/provider/package/zypper_spec.rb | 116 |
9 files changed, 617 insertions, 617 deletions
diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index 691749df9..26732a3f0 100755 --- a/spec/unit/provider/package/aix_spec.rb +++ b/spec/unit/provider/package/aix_spec.rb @@ -5,62 +5,62 @@ require File.dirname(__FILE__) + '/../../../spec_helper' provider_class = Puppet::Type.type(:package).provider(:aix) describe provider_class do - before(:each) do - # Create a mock resource - @resource = stub 'resource' + before(:each) do + # Create a mock resource + @resource = stub 'resource' - # A catch all; no parameters set - @resource.stubs(:[]).returns(nil) + # A catch all; no parameters set + @resource.stubs(:[]).returns(nil) - # But set name and source - @resource.stubs(:[]).with(:name).returns "mypackage" - @resource.stubs(:[]).with(:source).returns "mysource" - @resource.stubs(:[]).with(:ensure).returns :installed + # But set name and source + @resource.stubs(:[]).with(:name).returns "mypackage" + @resource.stubs(:[]).with(:source).returns "mysource" + @resource.stubs(:[]).with(:ensure).returns :installed - @provider = provider_class.new - @provider.resource = @resource - end - - [:install, :uninstall, :latest, :query, :update].each do |method| - it "should have a #{method} method" do - @provider.should respond_to(method) - end - end + @provider = provider_class.new + @provider.resource = @resource + end - it "should uninstall a package" do - @provider.expects(:installp).with('-gu', 'mypackage') - @provider.uninstall + [:install, :uninstall, :latest, :query, :update].each do |method| + it "should have a #{method} method" do + @provider.should respond_to(method) end + end - describe "when installing" do - it "should install a package" do - @resource.stubs(:should).with(:ensure).returns(:installed) - @provider.expects(:installp).with('-acgwXY', '-d', 'mysource', 'mypackage') - @provider.install - end + it "should uninstall a package" do + @provider.expects(:installp).with('-gu', 'mypackage') + @provider.uninstall + end - it "should install a specific package version" do - @resource.stubs(:should).with(:ensure).returns("1.2.3.4") - @provider.expects(:installp).with('-acgwXY', '-d', 'mysource', 'mypackage 1.2.3.4') - @provider.install - end + describe "when installing" do + it "should install a package" do + @resource.stubs(:should).with(:ensure).returns(:installed) + @provider.expects(:installp).with('-acgwXY', '-d', 'mysource', 'mypackage') + @provider.install end - describe "when finding the latest version" do - it "should return the current version when no later version is present" do - @provider.stubs(:latest_info).returns(nil) - @provider.stubs(:properties).returns( { :ensure => "1.2.3.4" } ) - @provider.latest.should == "1.2.3.4" - end + it "should install a specific package version" do + @resource.stubs(:should).with(:ensure).returns("1.2.3.4") + @provider.expects(:installp).with('-acgwXY', '-d', 'mysource', 'mypackage 1.2.3.4') + @provider.install + end + end - it "should return the latest version of a package" do - @provider.stubs(:latest_info).returns( { :version => "1.2.3.5" } ) - @provider.latest.should == "1.2.3.5" - end + describe "when finding the latest version" do + it "should return the current version when no later version is present" do + @provider.stubs(:latest_info).returns(nil) + @provider.stubs(:properties).returns( { :ensure => "1.2.3.4" } ) + @provider.latest.should == "1.2.3.4" end - it "update should install a package" do - @provider.expects(:install).with(false) - @provider.update + it "should return the latest version of a package" do + @provider.stubs(:latest_info).returns( { :version => "1.2.3.5" } ) + @provider.latest.should == "1.2.3.5" end + end + + it "update should install a package" do + @provider.expects(:install).with(false) + @provider.update + end end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index 54f2c0771..3c6bf62af 100755 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -5,141 +5,141 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f provider = Puppet::Type.type(:package).provider(:apt) describe provider do - before do - @resource = stub 'resource', :[] => "asdf" - @provider = provider.new(@resource) + before do + @resource = stub 'resource', :[] => "asdf" + @provider = provider.new(@resource) - @fakeresult = "install ok installed asdf 1.0\n" - end + @fakeresult = "install ok installed asdf 1.0\n" + end - it "should be versionable" do - provider.should be_versionable - end + it "should be versionable" do + provider.should be_versionable + end - it "should use :install to update" do - @provider.expects(:install) - @provider.update - end + it "should use :install to update" do + @provider.expects(:install) + @provider.update + end - it "should use 'apt-get remove' to uninstall" do - @provider.expects(:aptget).with("-y", "-q", :remove, "asdf") + it "should use 'apt-get remove' to uninstall" do + @provider.expects(:aptget).with("-y", "-q", :remove, "asdf") - @provider.uninstall - end + @provider.uninstall + end - it "should use 'apt-get purge' and 'dpkg purge' to purge" do - @provider.expects(:aptget).with("-y", "-q", :remove, "--purge", "asdf") - @provider.expects(:dpkg).with("--purge", "asdf") + it "should use 'apt-get purge' and 'dpkg purge' to purge" do + @provider.expects(:aptget).with("-y", "-q", :remove, "--purge", "asdf") + @provider.expects(:dpkg).with("--purge", "asdf") - @provider.purge - end + @provider.purge + end - it "should use 'apt-cache policy' to determine the latest version of a package" do - @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf: + it "should use 'apt-cache policy' to determine the latest version of a package" do + @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf: Installed: 1:1.0 Candidate: 1:1.1 Version table: 1:1.0 - 650 http://ftp.osuosl.org testing/main Packages + 650 http://ftp.osuosl.org testing/main Packages *** 1:1.1 - 100 /var/lib/dpkg/status" + 100 /var/lib/dpkg/status" - @provider.latest.should == "1:1.1" - end + @provider.latest.should == "1:1.1" + end - it "should print and error and return nil if no policy is found" do - @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf:" + it "should print and error and return nil if no policy is found" do + @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf:" - @provider.expects(:err) - @provider.latest.should be_nil - end + @provider.expects(:err) + @provider.latest.should be_nil + end - it "should be able to preseed" do - @provider.should respond_to(:run_preseed) - end + it "should be able to preseed" do + @provider.should respond_to(:run_preseed) + end - it "should preseed with the provided responsefile when preseeding is called for" do - @resource.expects(:[]).with(:responsefile).returns "/my/file" - FileTest.expects(:exist?).with("/my/file").returns true + it "should preseed with the provided responsefile when preseeding is called for" do + @resource.expects(:[]).with(:responsefile).returns "/my/file" + FileTest.expects(:exist?).with("/my/file").returns true - @provider.expects(:info) - @provider.expects(:preseed).with("/my/file") + @provider.expects(:info) + @provider.expects(:preseed).with("/my/file") - @provider.run_preseed - end + @provider.run_preseed + end - it "should not preseed if no responsefile is provided" do - @resource.expects(:[]).with(:responsefile).returns nil + it "should not preseed if no responsefile is provided" do + @resource.expects(:[]).with(:responsefile).returns nil - @provider.expects(:info) - @provider.expects(:preseed).never + @provider.expects(:info) + @provider.expects(:preseed).never - @provider.run_preseed - end + @provider.run_preseed + end - it "should fail if a cdrom is listed in the sources list and :allowcdrom is not specified" + it "should fail if a cdrom is listed in the sources list and :allowcdrom is not specified" - describe "when installing" do - it "should preseed if a responsefile is provided" do - @resource.expects(:[]).with(:responsefile).returns "/my/file" - @provider.expects(:run_preseed) + describe "when installing" do + it "should preseed if a responsefile is provided" do + @resource.expects(:[]).with(:responsefile).returns "/my/file" + @provider.expects(:run_preseed) - @provider.stubs(:aptget) - @provider.install - end + @provider.stubs(:aptget) + @provider.install + end - it "should check for a cdrom" do - @provider.expects(:checkforcdrom) + it "should check for a cdrom" do + @provider.expects(:checkforcdrom) - @provider.stubs(:aptget) - @provider.install - end + @provider.stubs(:aptget) + @provider.install + end - it "should use 'apt-get install' with the package name if no version is asked for" do - @resource.expects(:[]).with(:ensure).returns :installed - @provider.expects(:aptget).with { |*command| command[-1] == "asdf" and command[-2] == :install } + it "should use 'apt-get install' with the package name if no version is asked for" do + @resource.expects(:[]).with(:ensure).returns :installed + @provider.expects(:aptget).with { |*command| command[-1] == "asdf" and command[-2] == :install } - @provider.install - end + @provider.install + end - it "should specify the package version if one is asked for" do - @resource.expects(:[]).with(:ensure).returns "1.0" - @provider.expects(:aptget).with { |*command| command[-1] == "asdf=1.0" } + it "should specify the package version if one is asked for" do + @resource.expects(:[]).with(:ensure).returns "1.0" + @provider.expects(:aptget).with { |*command| command[-1] == "asdf=1.0" } - @provider.install - end + @provider.install + end - it "should use --force-yes if a package version is specified" do - @resource.expects(:[]).with(:ensure).returns "1.0" - @provider.expects(:aptget).with { |*command| command.include?("--force-yes") } + it "should use --force-yes if a package version is specified" do + @resource.expects(:[]).with(:ensure).returns "1.0" + @provider.expects(:aptget).with { |*command| command.include?("--force-yes") } - @provider.install - end + @provider.install + end - it "should do a quiet install" do - @provider.expects(:aptget).with { |*command| command.include?("-q") } + it "should do a quiet install" do + @provider.expects(:aptget).with { |*command| command.include?("-q") } - @provider.install - end + @provider.install + end - it "should default to 'yes' for all questions" do - @provider.expects(:aptget).with { |*command| command.include?("-y") } + it "should default to 'yes' for all questions" do + @provider.expects(:aptget).with { |*command| command.include?("-y") } - @provider.install - end + @provider.install + end - it "should keep config files if asked" do - @resource.expects(:[]).with(:configfiles).returns :keep - @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confold") } + it "should keep config files if asked" do + @resource.expects(:[]).with(:configfiles).returns :keep + @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confold") } - @provider.install - end + @provider.install + end - it "should replace config files if asked" do - @resource.expects(:[]).with(:configfiles).returns :replace - @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confnew") } + it "should replace config files if asked" do + @resource.expects(:[]).with(:configfiles).returns :replace + @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confnew") } - @provider.install - end + @provider.install end + end end diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 68ffb19a4..47ac9766e 100755 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -5,221 +5,221 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f provider = Puppet::Type.type(:package).provider(:dpkg) describe provider do - before do - @resource = stub 'resource', :[] => "asdf" - @provider = provider.new(@resource) - @provider.expects(:execute).never # forbid "manual" executions - - @fakeresult = "install ok installed asdf 1.0\n" - end - - it "should have documentation" do - provider.doc.should be_instance_of(String) - end - - describe "when listing all instances" do - before do - provider.stubs(:command).with(:dpkgquery).returns "myquery" - end + before do + @resource = stub 'resource', :[] => "asdf" + @provider = provider.new(@resource) + @provider.expects(:execute).never # forbid "manual" executions - it "should use dpkg-query" do - provider.expects(:command).with(:dpkgquery).returns "myquery" - provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").returns @fakeresult + @fakeresult = "install ok installed asdf 1.0\n" + end - provider.instances - end + it "should have documentation" do + provider.doc.should be_instance_of(String) + end - it "should create and return an instance with each parsed line from dpkg-query" do - pipe = mock 'pipe' - pipe.expects(:each).yields @fakeresult - provider.expects(:execpipe).yields pipe + describe "when listing all instances" do + before do + provider.stubs(:command).with(:dpkgquery).returns "myquery" + end - asdf = mock 'pkg1' - provider.expects(:new).with(:ensure => "1.0", :error => "ok", :desired => "install", :name => "asdf", :status => "installed", :provider => :dpkg).returns asdf + it "should use dpkg-query" do + provider.expects(:command).with(:dpkgquery).returns "myquery" + provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").returns @fakeresult - provider.instances.should == [asdf] - end + provider.instances + end - it "should warn on and ignore any lines it does not understand" do - pipe = mock 'pipe' - pipe.expects(:each).yields "foobar" - provider.expects(:execpipe).yields pipe + it "should create and return an instance with each parsed line from dpkg-query" do + pipe = mock 'pipe' + pipe.expects(:each).yields @fakeresult + provider.expects(:execpipe).yields pipe - Puppet.expects(:warning) - provider.expects(:new).never + asdf = mock 'pkg1' + provider.expects(:new).with(:ensure => "1.0", :error => "ok", :desired => "install", :name => "asdf", :status => "installed", :provider => :dpkg).returns asdf - provider.instances.should == [] - end + provider.instances.should == [asdf] end - describe "when querying the current state" do - it "should use dpkg-query" do - @provider.expects(:dpkgquery).with("-W", "--showformat",'${Status} ${Package} ${Version}\\n', "asdf").returns @fakeresult + it "should warn on and ignore any lines it does not understand" do + pipe = mock 'pipe' + pipe.expects(:each).yields "foobar" + provider.expects(:execpipe).yields pipe - @provider.query - end + Puppet.expects(:warning) + provider.expects(:new).never - it "should consider the package purged if dpkg-query fails" do - @provider.expects(:dpkgquery).raises Puppet::ExecutionFailure.new("eh") + provider.instances.should == [] + end + end - @provider.query[:ensure].should == :purged - end + describe "when querying the current state" do + it "should use dpkg-query" do + @provider.expects(:dpkgquery).with("-W", "--showformat",'${Status} ${Package} ${Version}\\n', "asdf").returns @fakeresult - it "should return a hash of the found status with the desired state, error state, status, name, and 'ensure'" do - @provider.expects(:dpkgquery).returns @fakeresult + @provider.query + end - @provider.query.should == {:ensure => "1.0", :error => "ok", :desired => "install", :name => "asdf", :status => "installed", :provider => :dpkg} - end + it "should consider the package purged if dpkg-query fails" do + @provider.expects(:dpkgquery).raises Puppet::ExecutionFailure.new("eh") - it "should consider the package absent if the dpkg-query result cannot be interpreted" do - @provider.expects(:dpkgquery).returns "somebaddata" + @provider.query[:ensure].should == :purged + end - @provider.query[:ensure].should == :absent - end + it "should return a hash of the found status with the desired state, error state, status, name, and 'ensure'" do + @provider.expects(:dpkgquery).returns @fakeresult - it "should fail if an error is discovered" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("ok", "error") + @provider.query.should == {:ensure => "1.0", :error => "ok", :desired => "install", :name => "asdf", :status => "installed", :provider => :dpkg} + end - lambda { @provider.query }.should raise_error(Puppet::Error) - end + it "should consider the package absent if the dpkg-query result cannot be interpreted" do + @provider.expects(:dpkgquery).returns "somebaddata" - it "should consider the package purged if it is marked 'not-installed'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "not-installed") + @provider.query[:ensure].should == :absent + end - @provider.query[:ensure].should == :purged - end + it "should fail if an error is discovered" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("ok", "error") - it "should consider the package absent if it is marked 'config-files'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "config-files") - @provider.query[:ensure].should == :absent - end + lambda { @provider.query }.should raise_error(Puppet::Error) + end - it "should consider the package absent if it is marked 'half-installed'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "half-installed") - @provider.query[:ensure].should == :absent - end + it "should consider the package purged if it is marked 'not-installed'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "not-installed") - it "should consider the package absent if it is marked 'unpacked'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "unpacked") - @provider.query[:ensure].should == :absent - end + @provider.query[:ensure].should == :purged + end - it "should consider the package absent if it is marked 'half-configured'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "half-configured") - @provider.query[:ensure].should == :absent - end + it "should consider the package absent if it is marked 'config-files'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "config-files") + @provider.query[:ensure].should == :absent + end - it "should consider the package held if its state is 'hold'" do - @provider.expects(:dpkgquery).returns @fakeresult.sub("install", "hold") - @provider.query[:ensure].should == :held - end + it "should consider the package absent if it is marked 'half-installed'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "half-installed") + @provider.query[:ensure].should == :absent end - it "should be able to install" do - @provider.should respond_to(:install) + it "should consider the package absent if it is marked 'unpacked'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "unpacked") + @provider.query[:ensure].should == :absent end - describe "when installing" do - before do - @resource.stubs(:[]).with(:source).returns "mypkg" - end + it "should consider the package absent if it is marked 'half-configured'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("installed", "half-configured") + @provider.query[:ensure].should == :absent + end - it "should fail to install if no source is specified in the resource" do - @resource.expects(:[]).with(:source).returns nil + it "should consider the package held if its state is 'hold'" do + @provider.expects(:dpkgquery).returns @fakeresult.sub("install", "hold") + @provider.query[:ensure].should == :held + end + end - lambda { @provider.install }.should raise_error(ArgumentError) - end + it "should be able to install" do + @provider.should respond_to(:install) + end - it "should use 'dpkg -i' to install the package" do - @resource.expects(:[]).with(:source).returns "mypackagefile" - @provider.expects(:unhold) - @provider.expects(:dpkg).with { |*command| command[-1] == "mypackagefile" and command[-2] == "-i" } + describe "when installing" do + before do + @resource.stubs(:[]).with(:source).returns "mypkg" + end - @provider.install - end + it "should fail to install if no source is specified in the resource" do + @resource.expects(:[]).with(:source).returns nil - it "should keep old config files if told to do so" do - @resource.expects(:[]).with(:configfiles).returns :keep - @provider.expects(:unhold) - @provider.expects(:dpkg).with { |*command| command[0] == "--force-confold" } + lambda { @provider.install }.should raise_error(ArgumentError) + end - @provider.install - end + it "should use 'dpkg -i' to install the package" do + @resource.expects(:[]).with(:source).returns "mypackagefile" + @provider.expects(:unhold) + @provider.expects(:dpkg).with { |*command| command[-1] == "mypackagefile" and command[-2] == "-i" } - it "should replace old config files if told to do so" do - @resource.expects(:[]).with(:configfiles).returns :replace - @provider.expects(:unhold) - @provider.expects(:dpkg).with { |*command| command[0] == "--force-confnew" } + @provider.install + end - @provider.install - end + it "should keep old config files if told to do so" do + @resource.expects(:[]).with(:configfiles).returns :keep + @provider.expects(:unhold) + @provider.expects(:dpkg).with { |*command| command[0] == "--force-confold" } - it "should ensure any hold is removed" do - @provider.expects(:unhold).once - @provider.expects(:dpkg) - @provider.install - end + @provider.install end - describe "when holding or unholding" do - before do - @tempfile = stub 'tempfile', :print => nil, :close => nil, :flush => nil, :path => "/other/file" - @tempfile.stubs(:write) - Tempfile.stubs(:new).returns @tempfile - end - - it "should install first if holding" do - @provider.stubs(:execute) - @provider.expects(:install).once - @provider.hold - end + it "should replace old config files if told to do so" do + @resource.expects(:[]).with(:configfiles).returns :replace + @provider.expects(:unhold) + @provider.expects(:dpkg).with { |*command| command[0] == "--force-confnew" } - it "should execute dpkg --set-selections when holding" do - @provider.stubs(:install) - @provider.expects(:execute).with([:dpkg, '--set-selections'], {:stdinfile => @tempfile.path}).once - @provider.hold - end + @provider.install + end - it "should execute dpkg --set-selections when unholding" do - @provider.stubs(:install) - @provider.expects(:execute).with([:dpkg, '--set-selections'], {:stdinfile => @tempfile.path}).once - @provider.hold - end + it "should ensure any hold is removed" do + @provider.expects(:unhold).once + @provider.expects(:dpkg) + @provider.install end + end - it "should use :install to update" do - @provider.expects(:install) - @provider.update + describe "when holding or unholding" do + before do + @tempfile = stub 'tempfile', :print => nil, :close => nil, :flush => nil, :path => "/other/file" + @tempfile.stubs(:write) + Tempfile.stubs(:new).returns @tempfile end - describe "when determining latest available version" do - it "should return the version found by dpkg-deb" do - @resource.expects(:[]).with(:source).returns "myfile" - @provider.expects(:dpkg_deb).with { |*command| command[-1] == "myfile" }.returns "asdf\t1.0" - @provider.latest.should == "1.0" - end + it "should install first if holding" do + @provider.stubs(:execute) + @provider.expects(:install).once + @provider.hold + end - it "should warn if the package file contains a different package" do - @provider.expects(:dpkg_deb).returns("foo\tversion") - @provider.expects(:warning) - @provider.latest - end + it "should execute dpkg --set-selections when holding" do + @provider.stubs(:install) + @provider.expects(:execute).with([:dpkg, '--set-selections'], {:stdinfile => @tempfile.path}).once + @provider.hold + end - it "should cope with names containing ++" do - @resource = stub 'resource', :[] => "asdf++" - @provider = provider.new(@resource) - @provider.expects(:dpkg_deb).returns "asdf++\t1.0" - @provider.latest.should == "1.0" - end + it "should execute dpkg --set-selections when unholding" do + @provider.stubs(:install) + @provider.expects(:execute).with([:dpkg, '--set-selections'], {:stdinfile => @tempfile.path}).once + @provider.hold + end + end + + it "should use :install to update" do + @provider.expects(:install) + @provider.update + end + + describe "when determining latest available version" do + it "should return the version found by dpkg-deb" do + @resource.expects(:[]).with(:source).returns "myfile" + @provider.expects(:dpkg_deb).with { |*command| command[-1] == "myfile" }.returns "asdf\t1.0" + @provider.latest.should == "1.0" end - it "should use 'dpkg -r' to uninstall" do - @provider.expects(:dpkg).with("-r", "asdf") - @provider.uninstall + it "should warn if the package file contains a different package" do + @provider.expects(:dpkg_deb).returns("foo\tversion") + @provider.expects(:warning) + @provider.latest end - it "should use 'dpkg --purge' to purge" do - @provider.expects(:dpkg).with("--purge", "asdf") - @provider.purge + it "should cope with names containing ++" do + @resource = stub 'resource', :[] => "asdf++" + @provider = provider.new(@resource) + @provider.expects(:dpkg_deb).returns "asdf++\t1.0" + @provider.latest.should == "1.0" end + end + + it "should use 'dpkg -r' to uninstall" do + @provider.expects(:dpkg).with("-r", "asdf") + @provider.uninstall + end + + it "should use 'dpkg --purge' to purge" do + @provider.expects(:dpkg).with("--purge", "asdf") + @provider.purge + end end diff --git a/spec/unit/provider/package/gem_spec.rb b/spec/unit/provider/package/gem_spec.rb index 3dc1fa347..063e1474b 100644 --- a/spec/unit/provider/package/gem_spec.rb +++ b/spec/unit/provider/package/gem_spec.rb @@ -5,83 +5,83 @@ require File.dirname(__FILE__) + '/../../../spec_helper' 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) + 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 = stub 'resource' + + # A catch all; no parameters set + @resource.stubs(:[]).returns nil + + # We have to set a name, though + @resource.stubs(:[]).with(:name).returns "myresource" + @resource.stubs(:[]).with(:ensure).returns :installed + + @provider = provider_class.new + @provider.stubs(:resource).returns @resource end - describe "when installing" do - before do - # Create a mock resource - @resource = stub 'resource' + it "should use the path to the gem" do + provider_class.stubs(:command).with(:gemcmd).returns "/my/gem" + @provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns "" + @provider.install + end - # A catch all; no parameters set - @resource.stubs(:[]).returns nil + it "should specify that the gem is being installed" do + @provider.expects(:execute).with { |args| args[1] == "install" }.returns "" + @provider.install + end - # We have to set a name, though - @resource.stubs(:[]).with(:name).returns "myresource" - @resource.stubs(:[]).with(:ensure).returns :installed + it "should specify that dependencies should be included" do + @provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns "" + @provider.install + end - @provider = provider_class.new - @provider.stubs(:resource).returns @resource - end + it "should specify the package name" do + @provider.expects(:execute).with { |args| args[3] == "myresource" }.returns "" + @provider.install + end - it "should use the path to the gem" do - provider_class.stubs(:command).with(:gemcmd).returns "/my/gem" - @provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns "" - @provider.install + describe "when a source is specified" do + describe "as a normal file" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "/my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install end - - it "should specify that the gem is being installed" do - @provider.expects(:execute).with { |args| args[1] == "install" }.returns "" - @provider.install + end + describe "as a file url" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "file:///my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install end - - it "should specify that dependencies should be included" do - @provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns "" - @provider.install + end + describe "as a puppet url" do + it "should fail" do + @resource.stubs(:[]).with(:source).returns "puppet://my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) end - - it "should specify the package name" do - @provider.expects(:execute).with { |args| args[3] == "myresource" }.returns "" - @provider.install + end + describe "as a non-file and non-puppet url" do + it "should treat the source as a gem repository" do + @resource.stubs(:[]).with(:source).returns "http://host/my/file" + @provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns "" + @provider.install end - - describe "when a source is specified" do - describe "as a normal file" do - it "should use the file name instead of the gem name" do - @resource.stubs(:[]).with(:source).returns "/my/file" - @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" - @provider.install - end - end - describe "as a file url" do - it "should use the file name instead of the gem name" do - @resource.stubs(:[]).with(:source).returns "file:///my/file" - @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" - @provider.install - end - end - describe "as a puppet url" do - it "should fail" do - @resource.stubs(:[]).with(:source).returns "puppet://my/file" - lambda { @provider.install }.should raise_error(Puppet::Error) - end - end - describe "as a non-file and non-puppet url" do - it "should treat the source as a gem repository" do - @resource.stubs(:[]).with(:source).returns "http://host/my/file" - @provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns "" - @provider.install - end - end - describe "with an invalid uri" do - it "should fail" do - URI.expects(:parse).raises(ArgumentError) - @resource.stubs(:[]).with(:source).returns "http:::::uppet:/:/my/file" - lambda { @provider.install }.should raise_error(Puppet::Error) - end - end + end + describe "with an invalid uri" do + it "should fail" do + URI.expects(:parse).raises(ArgumentError) + @resource.stubs(:[]).with(:source).returns "http:::::uppet:/:/my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) end + end end + end end diff --git a/spec/unit/provider/package/hpux_spec.rb b/spec/unit/provider/package/hpux_spec.rb index 8343c6052..e4ac22e21 100644 --- a/spec/unit/provider/package/hpux_spec.rb +++ b/spec/unit/provider/package/hpux_spec.rb @@ -5,48 +5,48 @@ require File.dirname(__FILE__) + '/../../../spec_helper' provider_class = Puppet::Type.type(:package).provider(:hpux) describe provider_class do - before(:each) do - # Create a mock resource - @resource = stub 'resource' - - # A catch all; no parameters set - @resource.stubs(:[]).returns(nil) - - # But set name and source - @resource.stubs(:[]).with(:name).returns "mypackage" - @resource.stubs(:[]).with(:source).returns "mysource" - @resource.stubs(:[]).with(:ensure).returns :installed - - @provider = provider_class.new - @provider.stubs(:resource).returns @resource - end - - it "should have an install method" do - @provider = provider_class.new - @provider.should respond_to(:install) - end - - it "should have an uninstall method" do - @provider = provider_class.new - @provider.should respond_to(:uninstall) - end - - it "should have a swlist method" do - @provider = provider_class.new - @provider.should respond_to(:swlist) - end - - describe "when installing" do - it "should use a command-line like 'swinstall -x mount_all_filesystems=false -s SOURCE PACKAGE-NAME'" do - @provider.expects(:swinstall).with('-x', 'mount_all_filesystems=false', '-s', 'mysource', 'mypackage') - @provider.install - end + before(:each) do + # Create a mock resource + @resource = stub 'resource' + + # A catch all; no parameters set + @resource.stubs(:[]).returns(nil) + + # But set name and source + @resource.stubs(:[]).with(:name).returns "mypackage" + @resource.stubs(:[]).with(:source).returns "mysource" + @resource.stubs(:[]).with(:ensure).returns :installed + + @provider = provider_class.new + @provider.stubs(:resource).returns @resource + end + + it "should have an install method" do + @provider = provider_class.new + @provider.should respond_to(:install) + end + + it "should have an uninstall method" do + @provider = provider_class.new + @provider.should respond_to(:uninstall) + end + + it "should have a swlist method" do + @provider = provider_class.new + @provider.should respond_to(:swlist) + end + + describe "when installing" do + it "should use a command-line like 'swinstall -x mount_all_filesystems=false -s SOURCE PACKAGE-NAME'" do + @provider.expects(:swinstall).with('-x', 'mount_all_filesystems=false', '-s', 'mysource', 'mypackage') + @provider.install end + end - describe "when uninstalling" do - it "should use a command-line like 'swremove -x mount_all_filesystems=false PACKAGE-NAME'" do - @provider.expects(:swremove).with('-x', 'mount_all_filesystems=false', 'mypackage') - @provider.uninstall - end + describe "when uninstalling" do + it "should use a command-line like 'swremove -x mount_all_filesystems=false PACKAGE-NAME'" do + @provider.expects(:swremove).with('-x', 'mount_all_filesystems=false', 'mypackage') + @provider.uninstall end + end end diff --git a/spec/unit/provider/package/nim_spec.rb b/spec/unit/provider/package/nim_spec.rb index 5d9083b70..53a9cc839 100755 --- a/spec/unit/provider/package/nim_spec.rb +++ b/spec/unit/provider/package/nim_spec.rb @@ -5,38 +5,38 @@ require File.dirname(__FILE__) + '/../../../spec_helper' provider_class = Puppet::Type.type(:package).provider(:nim) describe provider_class do - before(:each) do - # Create a mock resource - @resource = stub 'resource' - - # A catch all; no parameters set - @resource.stubs(:[]).returns(nil) - - # But set name and source - @resource.stubs(:[]).with(:name).returns "mypackage" - @resource.stubs(:[]).with(:source).returns "mysource" - @resource.stubs(:[]).with(:ensure).returns :installed - - @provider = provider_class.new - @provider.resource = @resource - end - - it "should have an install method" do - @provider = provider_class.new - @provider.should respond_to(:install) + before(:each) do + # Create a mock resource + @resource = stub 'resource' + + # A catch all; no parameters set + @resource.stubs(:[]).returns(nil) + + # But set name and source + @resource.stubs(:[]).with(:name).returns "mypackage" + @resource.stubs(:[]).with(:source).returns "mysource" + @resource.stubs(:[]).with(:ensure).returns :installed + + @provider = provider_class.new + @provider.resource = @resource + end + + it "should have an install method" do + @provider = provider_class.new + @provider.should respond_to(:install) + end + + describe "when installing" do + it "should install a package" do + @resource.stubs(:should).with(:ensure).returns(:installed) + @provider.expects(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets='mypackage'") + @provider.install end - describe "when installing" do - it "should install a package" do - @resource.stubs(:should).with(:ensure).returns(:installed) - @provider.expects(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets='mypackage'") - @provider.install - end - - it "should install a versioned package" do - @resource.stubs(:should).with(:ensure).returns("1.2.3.4") - @provider.expects(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets='mypackage 1.2.3.4'") - @provider.install - end + it "should install a versioned package" do + @resource.stubs(:should).with(:ensure).returns("1.2.3.4") + @provider.expects(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets='mypackage 1.2.3.4'") + @provider.install end + end end diff --git a/spec/unit/provider/package/pkg_spec.rb b/spec/unit/provider/package/pkg_spec.rb index b29405e26..1544b8b7e 100644 --- a/spec/unit/provider/package/pkg_spec.rb +++ b/spec/unit/provider/package/pkg_spec.rb @@ -5,59 +5,59 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f provider = Puppet::Type.type(:package).provider(:pkg) describe provider do - before do - @resource = stub 'resource', :[] => "dummy" - @provider = provider.new(@resource) - - @fakeresult = "install ok installed dummy 1.0\n" - end - - def self.it_should_respond_to(*actions) - actions.each do |action| - it "should respond to :#{action}" do - @provider.should respond_to(action) - end - end - end - - it_should_respond_to :install, :uninstall, :update, :query, :latest - - it "should be versionable" do - provider.should_not be_versionable - end - - it "should use :install to update" do - @provider.expects(:install) - @provider.update - end - - it "should parse a line correctly" do - result = provider.parse_line("dummy 1.0@1.0-1.0 installed ----") - result.should == {:name => "dummy", :version => "1.0@1.0-1.0", - :ensure => :present, :status => "installed", - :provider => :pkg, :error => "ok"} - end - - it "should fail to parse an incorrect line" do - result = provider.parse_line("foo") - result.should be_nil - end - - it "should fail to list a missing package" do - @provider.expects(:pkg).with(:list, "-H", "dummy").returns "1" - @provider.query.should == {:status=>"missing", :ensure=>:absent, - :name=>"dummy", :error=>"ok"} - end - - it "should fail to list a package when it can't parse the output line" do - @provider.expects(:pkg).with(:list, "-H", "dummy").returns "failed" - @provider.query.should == {:status=>"missing", :ensure=>:absent, :name=>"dummy", :error=>"ok"} - end - - it "should list package correctly" do - @provider.expects(:pkg).with(:list, "-H", "dummy").returns "dummy 1.0@1.0-1.0 installed ----" - @provider.query.should == {:name => "dummy", :version => "1.0@1.0-1.0", - :ensure => :present, :status => "installed", - :provider => :pkg, :error => "ok"} - end + before do + @resource = stub 'resource', :[] => "dummy" + @provider = provider.new(@resource) + + @fakeresult = "install ok installed dummy 1.0\n" + end + + def self.it_should_respond_to(*actions) + actions.each do |action| + it "should respond to :#{action}" do + @provider.should respond_to(action) + end + end + end + + it_should_respond_to :install, :uninstall, :update, :query, :latest + + it "should be versionable" do + provider.should_not be_versionable + end + + it "should use :install to update" do + @provider.expects(:install) + @provider.update + end + + it "should parse a line correctly" do + result = provider.parse_line("dummy 1.0@1.0-1.0 installed ----") + result.should == {:name => "dummy", :version => "1.0@1.0-1.0", + :ensure => :present, :status => "installed", + :provider => :pkg, :error => "ok"} + end + + it "should fail to parse an incorrect line" do + result = provider.parse_line("foo") + result.should be_nil + end + + it "should fail to list a missing package" do + @provider.expects(:pkg).with(:list, "-H", "dummy").returns "1" + @provider.query.should == {:status=>"missing", :ensure=>:absent, + :name=>"dummy", :error=>"ok"} + end + + it "should fail to list a package when it can't parse the output line" do + @provider.expects(:pkg).with(:list, "-H", "dummy").returns "failed" + @provider.query.should == {:status=>"missing", :ensure=>:absent, :name=>"dummy", :error=>"ok"} + end + + it "should list package correctly" do + @provider.expects(:pkg).with(:list, "-H", "dummy").returns "dummy 1.0@1.0-1.0 installed ----" + @provider.query.should == {:name => "dummy", :version => "1.0@1.0-1.0", + :ensure => :present, :status => "installed", + :provider => :pkg, :error => "ok"} + end end diff --git a/spec/unit/provider/package/pkgdmg_spec.rb b/spec/unit/provider/package/pkgdmg_spec.rb index d4c5a9287..1fd5b4ac4 100755 --- a/spec/unit/provider/package/pkgdmg_spec.rb +++ b/spec/unit/provider/package/pkgdmg_spec.rb @@ -5,80 +5,80 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f provider = Puppet::Type.type(:package).provider(:pkgdmg) describe provider do - before do - @resource = stub 'resource', :[] => "dummypkgdmg" - @provider = provider.new(@resource) - - @fakemountpoint = "/tmp/dmg.foo" - @fakepkgfile = "/tmp/test.pkg" - @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] } - @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo) - - @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly", - "-noidme", "-mountrandom", "/tmp"] + before do + @resource = stub 'resource', :[] => "dummypkgdmg" + @provider = provider.new(@resource) + + @fakemountpoint = "/tmp/dmg.foo" + @fakepkgfile = "/tmp/test.pkg" + @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] } + @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo) + + @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly", + "-noidme", "-mountrandom", "/tmp"] + end + + it "should not be versionable" do + provider.versionable?.should be_false + end + + it "should not be uninstallable" do + provider.uninstallable?.should be_false + end + + describe "when installing it should fail when" do + it "no source is specified" do + @resource.stubs(:[]).with(:source).returns nil + lambda { @provider.install }.should raise_error(Puppet::Error) end - it "should not be versionable" do - provider.versionable?.should be_false + it "no name is specified" do + @resource.stubs(:[]).with(:name).returns nil + lambda { @provider.install }.should raise_error(Puppet::Error) end - it "should not be uninstallable" do - provider.uninstallable?.should be_false + it "the source does not end in .dmg or .pkg" do + @resource.stubs(:[]).with(:source).returns "notendingindotdmgorpkg" + lambda { @provider.install }.should raise_error(Puppet::Error) end - describe "when installing it should fail when" do - it "no source is specified" do - @resource.stubs(:[]).with(:source).returns nil - lambda { @provider.install }.should raise_error(Puppet::Error) - end - - it "no name is specified" do - @resource.stubs(:[]).with(:name).returns nil - lambda { @provider.install }.should raise_error(Puppet::Error) - end - - it "the source does not end in .dmg or .pkg" do - @resource.stubs(:[]).with(:source).returns "notendingindotdmgorpkg" - lambda { @provider.install }.should raise_error(Puppet::Error) - end - - it "a disk image with no system entities is mounted" do - @provider.stubs(:[]).with(:hdiutil).returns "" - lambda { @provider.install }.should raise_error(Puppet::Error) - end + it "a disk image with no system entities is mounted" do + @provider.stubs(:[]).with(:hdiutil).returns "" + lambda { @provider.install }.should raise_error(Puppet::Error) end + end - # These tests shouldn't be this messy. The pkgdmg provider needs work... - describe "when installing a pkgdmg" do - before do - fh = mock 'filehandle' - fh.stubs(:path).yields "/tmp/foo" - @resource.stubs(:[]).with(:source).returns "foo.dmg" - File.stubs(:open).yields fh - end - - it "should call hdiutil to mount and eject the disk image" do - Dir.stubs(:entries).returns [] - @provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0 - @provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist - @provider.install - end + # These tests shouldn't be this messy. The pkgdmg provider needs work... + describe "when installing a pkgdmg" do + before do + fh = mock 'filehandle' + fh.stubs(:path).yields "/tmp/foo" + @resource.stubs(:[]).with(:source).returns "foo.dmg" + File.stubs(:open).yields fh + end - it "should call installpkg if a pkg/mpkg is found on the dmg" do - Dir.stubs(:entries).returns ["foo.pkg"] - @provider.class.stubs(:hdiutil).returns @fakehdiutilplist - @provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns "" - @provider.install - end + it "should call hdiutil to mount and eject the disk image" do + Dir.stubs(:entries).returns [] + @provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0 + @provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist + @provider.install end - describe "when installing flat pkg file" do - it "should call installpkg if a flat pkg file is found instead of a .dmg image" do - @resource.stubs(:[]).with(:source).returns "/tmp/test.pkg" - @resource.stubs(:[]).with(:name).returns "testpkg" - @provider.class.expects(:installpkgdmg).with("#{@fakepkgfile}", "testpkg").returns "" - @provider.install - end + it "should call installpkg if a pkg/mpkg is found on the dmg" do + Dir.stubs(:entries).returns ["foo.pkg"] + @provider.class.stubs(:hdiutil).returns @fakehdiutilplist + @provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns "" + @provider.install end + end + + describe "when installing flat pkg file" do + it "should call installpkg if a flat pkg file is found instead of a .dmg image" do + @resource.stubs(:[]).with(:source).returns "/tmp/test.pkg" + @resource.stubs(:[]).with(:name).returns "testpkg" + @provider.class.expects(:installpkgdmg).with("#{@fakepkgfile}", "testpkg").returns "" + @provider.install + end + end end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index b7f3687c6..5ac13b659 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -5,77 +5,77 @@ require File.dirname(__FILE__) + '/../../../spec_helper' provider_class = Puppet::Type.type(:package).provider(:zypper) describe provider_class do - before(:each) do - # Create a mock resource - @resource = stub 'resource' - - # A catch all; no parameters set - @resource.stubs(:[]).returns(nil) - - # But set name and source - @resource.stubs(:[]).with(:name).returns "mypackage" - @resource.stubs(:[]).with(:ensure).returns :installed - @resource.stubs(:command).with(:zypper).returns "/usr/bin/zypper" - - @provider = provider_class.new(@resource) - end - - it "should have an install method" do - @provider = provider_class.new - @provider.should respond_to(:install) - end - - it "should have a latest method" do - @provider = provider_class.new - @provider.should respond_to(:uninstall) - end - - it "should have an update method" do - @provider = provider_class.new - @provider.should respond_to(:update) - end - - it "should have a latest method" do - @provider = provider_class.new - @provider.should respond_to(:latest) + before(:each) do + # Create a mock resource + @resource = stub 'resource' + + # A catch all; no parameters set + @resource.stubs(:[]).returns(nil) + + # But set name and source + @resource.stubs(:[]).with(:name).returns "mypackage" + @resource.stubs(:[]).with(:ensure).returns :installed + @resource.stubs(:command).with(:zypper).returns "/usr/bin/zypper" + + @provider = provider_class.new(@resource) + end + + it "should have an install method" do + @provider = provider_class.new + @provider.should respond_to(:install) + end + + it "should have a latest method" do + @provider = provider_class.new + @provider.should respond_to(:uninstall) + end + + it "should have an update method" do + @provider = provider_class.new + @provider.should respond_to(:update) + end + + it "should have a latest method" do + @provider = provider_class.new + @provider.should respond_to(:latest) + end + + describe "when installing" do + it "should use a command-line with versioned package'" do + @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6" + @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage-1.2.3-4.5.6') + @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64" + @provider.install end - describe "when installing" do - it "should use a command-line with versioned package'" do - @resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6" - @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage-1.2.3-4.5.6') - @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64" - @provider.install - end - - it "should use a command-line without versioned package" do - @resource.stubs(:should).with(:ensure).returns :latest - @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage') - @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64" - @provider.install - end + it "should use a command-line without versioned package" do + @resource.stubs(:should).with(:ensure).returns :latest + @provider.expects(:zypper).with('--quiet', :install, '-l', '-y', 'mypackage') + @provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64" + @provider.install end + end - describe "when updating" do - it "should call install method of instance" do - @provider.expects(:install) - @provider.update - end + describe "when updating" do + it "should call install method of instance" do + @provider.expects(:install) + @provider.update end + end - describe "when getting latest version" do - it "should return a version string" do + describe "when getting latest version" do + it "should return a version string" do - fake_data = "Loading repository data... + fake_data = "Loading repository data... Reading installed packages... S | Repository | Name | Version | Arch --+----------------+-----------------------+-----------------+------- v | SLES11-Updates | cups | 1.1.1 | x86_64 v | SLES11-Updates | mypackage | 1.3.9h-8.20.1 | x86_64" - @provider.expects(:zypper).with("list-updates").returns fake_data - @provider.latest.should == "1.3.9h-8.20.1" - end + @provider.expects(:zypper).with("list-updates").returns fake_data + @provider.latest.should == "1.3.9h-8.20.1" end + end end |