Skip to content

Commit

Permalink
CHEF-3555: fix knife cookbook site install when String
Browse files Browse the repository at this point in the history
Ensure we turn cookbook_path into an Array before calling #first on it,
as this does not work in Ruby 1.9+

H/T Aaron Kalin for the fix
  • Loading branch information
btm committed Dec 3, 2012
1 parent c536fb7 commit eca4fd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chef/lib/chef/knife/cookbook_site_install.rb
Expand Up @@ -74,7 +74,7 @@ def run
@cookbook_name = parse_name_args!
# Check to ensure we have a valid source of cookbooks before continuing
#
@install_path = File.expand_path(config[:cookbook_path].first)
@install_path = File.expand_path(Array(config[:cookbook_path]).first)
ui.info "Installing #@cookbook_name to #{@install_path}"

@repo = CookbookSCMRepo.new(@install_path, ui, config)
Expand Down
14 changes: 12 additions & 2 deletions chef/spec/unit/knife/cookbook_site_install_spec.rb
Expand Up @@ -60,7 +60,6 @@


describe "run" do

it "should return an error if a cookbook name is not provided" do
@knife.name_args = []
@knife.ui.should_receive(:error).with("Please specify a cookbook to download and install.")
Expand Down Expand Up @@ -91,7 +90,6 @@
lambda { @knife.run }.should raise_error(SystemExit)
end


it "should install the specified version if second argument is a three-digit version" do
@knife.name_args = ["getting-started", "0.1.0"]
@knife.config[:no_deps] = true
Expand Down Expand Up @@ -134,5 +132,17 @@
@repo.should_not_receive(:reset_to_default_state)
@knife.run
end

it "should not raise an error if cookbook_path is a string" do
@knife.config[:cookbook_path] = '/var/tmp/chef'
@knife.config[:no_deps] = true
@knife.name_args = ["getting-started"]
upstream_file = File.join(@install_path, "getting-started.tar.gz")
@knife.should_receive(:download_cookbook_to).with(upstream_file)
@knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
@knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
@repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
lambda { @knife.run }.should_not raise_error
end
end
end

0 comments on commit eca4fd7

Please sign in to comment.