Skip to content

Commit b8ebb42

Browse files
danielsdeleoAJ Christensen
authored andcommitted
Fix CHEF-565 and de-mockify specs a little
1 parent 03214fa commit b8ebb42

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

‎chef/lib/chef/provider/package/dpkg.rb‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ def load_current_resource
4040
Chef::Log.debug("Checking dpkg status for #{@new_resource.package_name}")
4141
status = popen4("dpkg-deb -W #{@new_resource.source}") do |pid, stdin, stdout, stderr|
4242
stdout.each do |line|
43-
case line
44-
when /([\w\d]+)\t([\w\d.-]+)/
45-
@current_resource.package_name($1)
46-
@new_resource.version($2)
43+
if pkginfo = /([a-z\d\-\+]+)\t([\w\d.-]+)/.match(line)
44+
@current_resource.package_name(pkginfo[1])
45+
@new_resource.version(pkginfo[2])
4746
end
4847
end
4948
end

‎chef/spec/unit/provider/package/dpkg_spec.rb‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@
2929
:updated => nil,
3030
:source => "/tmp/wget_1.11.4-1ubuntu1_amd64.deb"
3131
)
32-
@current_resource = mock("Chef::Resource::Package",
33-
:null_object => true,
34-
:name => "wget",
35-
:version => nil,
36-
:package_name => nil,
37-
:updated => nil
38-
)
3932

4033
@provider = Chef::Provider::Package::Dpkg.new(@node, @new_resource)
41-
Chef::Resource::Package.stub!(:new).and_return(@current_resource)
4234

4335
@stdin = mock("STDIN", :null_object => true)
4436
@stdout = mock("STDOUT", :null_object => true)
@@ -51,15 +43,10 @@
5143
end
5244

5345
it "should create a current resource with the name of the new_resource" do
54-
Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
5546
@provider.load_current_resource
47+
@provider.current_resource.package_name.should == "wget"
5648
end
5749

58-
it "should set the current resources package name to the new resources package name" do
59-
@current_resource.should_receive(:package_name).with(@new_resource.package_name)
60-
@provider.load_current_resource
61-
end
62-
6350
it "should raise an exception if a source is supplied but not found" do
6451
::File.stub!(:exists?).and_return(false)
6552
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
@@ -68,9 +55,16 @@
6855
it "should get the source package version from dpkg-deb if provided" do
6956
@stdout.stub!(:each).and_yield("wget\t1.11.4-1ubuntu1")
7057
@provider.stub!(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
71-
@current_resource.should_receive(:package_name).with("wget")
7258
@new_resource.should_receive(:version).with("1.11.4-1ubuntu1")
7359
@provider.load_current_resource
60+
@provider.current_resource.package_name.should == "wget"
61+
end
62+
63+
it "gets the source package name from dpkg-deb correctly when the package name has `-' or `+' characters" do
64+
@stdout.stub!(:each).and_yield("foo-pkg++2\t1.11.4-1ubuntu1")
65+
@provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
66+
@provider.load_current_resource
67+
@provider.current_resource.package_name.should == "foo-pkg++2"
7468
end
7569

7670
it "should raise an exception if the source is not set but we are installing" do
@@ -99,11 +93,12 @@
9993
and_yield("Config-Version: 1.11.4-1ubuntu1").
10094
and_yield("Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5)").
10195
and_yield("Conflicts: wget-ssl")
102-
@provider.stub!(:popen4).with("dpkg -s #{@current_resource.package_name}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
103-
@current_resource.should_receive(:version).with("1.11.4-1ubuntu1")
96+
@provider.stub!(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
97+
10498
@provider.load_current_resource
99+
@provider.current_resource.version.should == "1.11.4-1ubuntu1"
105100
end
106-
101+
107102
it "should raise an exception if dpkg fails to run" do
108103
@status = mock("Status", :exitstatus => -1)
109104
@provider.stub!(:popen4).and_return(@status)

0 commit comments

Comments
 (0)