diff options
Diffstat (limited to 'spec/unit/knife/cookbook_site_install_spec.rb')
-rw-r--r-- | spec/unit/knife/cookbook_site_install_spec.rb | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index ff87a81b49..c4bd8f67d2 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::CookbookSiteInstall do require 'chef/knife/core/cookbook_scm_repo' @stdout = StringIO.new @knife = Chef::Knife::CookbookSiteInstall.new - @knife.ui.stub(:stdout).and_return(@stdout) + allow(@knife.ui).to receive(:stdout).and_return(@stdout) @knife.config = {} if Chef::Platform.windows? @install_path = 'C:/tmp/chef' @@ -34,18 +34,18 @@ describe Chef::Knife::CookbookSiteInstall do @stdout = StringIO.new @stderr = StringIO.new - @knife.stub(:stderr).and_return(@stdout) - @knife.stub(:stdout).and_return(@stdout) + allow(@knife).to receive(:stderr).and_return(@stdout) + allow(@knife).to receive(:stdout).and_return(@stdout) #Assume all external commands would have succeed. :( - File.stub(:unlink) - File.stub(:rmtree) - @knife.stub(:shell_out!).and_return(true) + allow(File).to receive(:unlink) + allow(File).to receive(:rmtree) + allow(@knife).to receive(:shell_out!).and_return(true) #CookbookSiteDownload Stup @downloader = {} - @knife.stub(:download_cookbook_to).and_return(@downloader) - @downloader.stub(:version).and_return do + allow(@knife).to receive(:download_cookbook_to).and_return(@downloader) + allow(@downloader).to receive(:version) do if @knife.name_args.size == 2 @knife.name_args[1] else @@ -57,49 +57,49 @@ describe Chef::Knife::CookbookSiteInstall do @repo = double(:sanity_check => true, :reset_to_default_state => true, :prepare_to_import => true, :finalize_updates_to => true, :merge_updates_from => true) - Chef::Knife::CookbookSCMRepo.stub(:new).and_return(@repo) + allow(Chef::Knife::CookbookSCMRepo).to receive(:new).and_return(@repo) end 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.") - lambda { @knife.run }.should raise_error(SystemExit) + expect(@knife.ui).to receive(:error).with("Please specify a cookbook to download and install.") + expect { @knife.run }.to raise_error(SystemExit) end it "should return an error if more than two arguments are given" do @knife.name_args = ["foo", "bar", "baz"] - @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.") - lambda { @knife.run }.should raise_error(SystemExit) + expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") + expect { @knife.run }.to raise_error(SystemExit) end it "should return an error if the second argument is not a version" do @knife.name_args = ["getting-started", "1pass"] - @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.") - lambda { @knife.run }.should raise_error(SystemExit) + expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") + expect { @knife.run }.to raise_error(SystemExit) end it "should return an error if the second argument is a four-digit version" do @knife.name_args = ["getting-started", "0.0.0.1"] - @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.") - lambda { @knife.run }.should raise_error(SystemExit) + expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") + expect { @knife.run }.to raise_error(SystemExit) end it "should return an error if the second argument is a one-digit version" do @knife.name_args = ["getting-started", "1"] - @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.") - lambda { @knife.run }.should raise_error(SystemExit) + expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") + expect { @knife.run }.to 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 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.1.0") - @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) - @repo.should_receive(:merge_updates_from).with("getting-started", "0.1.0") + expect(@knife).to receive(:download_cookbook_to).with(upstream_file) + expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.1.0") + expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) + expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.1.0") @knife.run end @@ -107,10 +107,10 @@ describe Chef::Knife::CookbookSiteInstall do @knife.name_args = ["getting-started", "0.1"] @knife.config[:no_deps] = true 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.1") - @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) - @repo.should_receive(:merge_updates_from).with("getting-started", "0.1") + expect(@knife).to receive(:download_cookbook_to).with(upstream_file) + expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.1") + expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) + expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.1") @knife.run end @@ -118,10 +118,10 @@ describe Chef::Knife::CookbookSiteInstall do @knife.name_args = ["getting-started"] @knife.config[:no_deps] = true 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") + expect(@knife).to receive(:download_cookbook_to).with(upstream_file) + expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0") + expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) + expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.3.0") @knife.run end @@ -130,8 +130,8 @@ describe Chef::Knife::CookbookSiteInstall do @knife.config[:use_current_branch] = true @knife.config[:no_deps] = true upstream_file = File.join(@install_path, "getting-started.tar.gz") - @repo.should_not_receive(:prepare_to_import) - @repo.should_not_receive(:reset_to_default_state) + expect(@repo).not_to receive(:prepare_to_import) + expect(@repo).not_to receive(:reset_to_default_state) @knife.run end @@ -140,11 +140,11 @@ describe Chef::Knife::CookbookSiteInstall do @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 + expect(@knife).to receive(:download_cookbook_to).with(upstream_file) + expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0") + expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started")) + expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.3.0") + expect { @knife.run }.not_to raise_error end end end |