diff options
author | Dan DeLeo <danielsdeleo@mac.com> | 2009-10-13 20:01:14 -0600 |
---|---|---|
committer | AJ Christensen <aj@opscode.com> | 2009-10-14 15:19:30 +1300 |
commit | b8ebb42d8be6d4b16daff6effdf1509875177000 (patch) | |
tree | 5c04c596fb86d4f8921219ea3f9c845b02667842 /chef/spec/unit/provider/package/dpkg_spec.rb | |
parent | 03214fa3eae3f5ccfdceb405fd66660566b005fb (diff) | |
download | chef-b8ebb42d8be6d4b16daff6effdf1509875177000.tar.gz |
Fix CHEF-565 and de-mockify specs a little
Diffstat (limited to 'chef/spec/unit/provider/package/dpkg_spec.rb')
-rw-r--r-- | chef/spec/unit/provider/package/dpkg_spec.rb | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/chef/spec/unit/provider/package/dpkg_spec.rb b/chef/spec/unit/provider/package/dpkg_spec.rb index d7985e3ea9..74865a1b5d 100644 --- a/chef/spec/unit/provider/package/dpkg_spec.rb +++ b/chef/spec/unit/provider/package/dpkg_spec.rb @@ -29,16 +29,8 @@ describe Chef::Provider::Package::Dpkg, "load_current_resource" do :updated => nil, :source => "/tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - @current_resource = mock("Chef::Resource::Package", - :null_object => true, - :name => "wget", - :version => nil, - :package_name => nil, - :updated => nil - ) @provider = Chef::Provider::Package::Dpkg.new(@node, @new_resource) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) @stdin = mock("STDIN", :null_object => true) @stdout = mock("STDOUT", :null_object => true) @@ -51,15 +43,10 @@ describe Chef::Provider::Package::Dpkg, "load_current_resource" do end it "should create a current resource with the name of the new_resource" do - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) @provider.load_current_resource + @provider.current_resource.package_name.should == "wget" end - it "should set the current resources package name to the new resources package name" do - @current_resource.should_receive(:package_name).with(@new_resource.package_name) - @provider.load_current_resource - end - it "should raise an exception if a source is supplied but not found" do ::File.stub!(:exists?).and_return(false) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) @@ -68,9 +55,16 @@ describe Chef::Provider::Package::Dpkg, "load_current_resource" do it "should get the source package version from dpkg-deb if provided" do @stdout.stub!(:each).and_yield("wget\t1.11.4-1ubuntu1") @provider.stub!(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @current_resource.should_receive(:package_name).with("wget") @new_resource.should_receive(:version).with("1.11.4-1ubuntu1") @provider.load_current_resource + @provider.current_resource.package_name.should == "wget" + end + + it "gets the source package name from dpkg-deb correctly when the package name has `-' or `+' characters" do + @stdout.stub!(:each).and_yield("foo-pkg++2\t1.11.4-1ubuntu1") + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.load_current_resource + @provider.current_resource.package_name.should == "foo-pkg++2" end it "should raise an exception if the source is not set but we are installing" do @@ -99,11 +93,12 @@ describe Chef::Provider::Package::Dpkg, "load_current_resource" do and_yield("Config-Version: 1.11.4-1ubuntu1"). and_yield("Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5)"). and_yield("Conflicts: wget-ssl") - @provider.stub!(:popen4).with("dpkg -s #{@current_resource.package_name}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @current_resource.should_receive(:version).with("1.11.4-1ubuntu1") + @provider.stub!(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.load_current_resource + @provider.current_resource.version.should == "1.11.4-1ubuntu1" end - + it "should raise an exception if dpkg fails to run" do @status = mock("Status", :exitstatus => -1) @provider.stub!(:popen4).and_return(@status) |