diff options
Diffstat (limited to 'spec/unit/knife/core/cookbook_scm_repo_spec.rb')
-rw-r--r-- | spec/unit/knife/core/cookbook_scm_repo_spec.rb | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/spec/unit/knife/core/cookbook_scm_repo_spec.rb b/spec/unit/knife/core/cookbook_scm_repo_spec.rb index 69da5400b0..2d66df31c1 100644 --- a/spec/unit/knife/core/cookbook_scm_repo_spec.rb +++ b/spec/unit/knife/core/cookbook_scm_repo_spec.rb @@ -39,45 +39,45 @@ BRANCHES end it "has a path to the cookbook repo" do - @cookbook_repo.repo_path.should == @repo_path + expect(@cookbook_repo.repo_path).to eq(@repo_path) end it "has a default branch" do - @cookbook_repo.default_branch.should == 'master' + expect(@cookbook_repo.default_branch).to eq('master') end describe "when sanity checking the repo" do it "exits when the directory does not exist" do - ::File.should_receive(:directory?).with(@repo_path).and_return(false) - lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit) + expect(::File).to receive(:directory?).with(@repo_path).and_return(false) + expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end describe "and the repo dir exists" do before do - ::File.stub(:directory?).with(@repo_path).and_return(true) + allow(::File).to receive(:directory?).with(@repo_path).and_return(true) end it "exits when there is no git repo" do - ::File.stub(:directory?).with(/.*\.git/).and_return(false) - lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit) + allow(::File).to receive(:directory?).with(/.*\.git/).and_return(false) + expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end describe "and the repo is a git repo" do before do - ::File.stub(:directory?).with(File.join(@repo_path, '.git')).and_return(true) + allow(::File).to receive(:directory?).with(File.join(@repo_path, '.git')).and_return(true) end it "exits when the default branch doesn't exist" do @nobranches = Mixlib::ShellOut.new.tap {|s|s.stdout.replace "\n"} - @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@nobranches) - lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit) + expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@nobranches) + expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end describe "and the default branch exists" do before do @master_branch = Mixlib::ShellOut.new @master_branch.stdout.replace "* master\n" - @cookbook_repo.should_receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@master_branch) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@master_branch) end it "exits when the git repo is dirty" do @@ -85,14 +85,14 @@ BRANCHES @dirty_status.stdout.replace(<<-DIRTY) M chef/lib/chef/knife/cookbook_site_vendor.rb DIRTY - @cookbook_repo.should_receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@dirty_status) - lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit) + expect(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@dirty_status) + expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end describe "and the repo is clean" do before do @clean_status = Mixlib::ShellOut.new.tap {|s| s.stdout.replace("\n")} - @cookbook_repo.stub(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status) + allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status) end it "passes the sanity check" do @@ -106,35 +106,35 @@ DIRTY end it "resets to default state by checking out the default branch" do - @cookbook_repo.should_receive(:shell_out!).with('git checkout master', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with('git checkout master', :cwd => @repo_path) @cookbook_repo.reset_to_default_state end it "determines if a the pristine copy branch exists" do - @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - @cookbook_repo.branch_exists?("chef-vendor-apache2").should be_true - @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - @cookbook_repo.branch_exists?("chef-vendor-nginx").should be_false + expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo.branch_exists?("chef-vendor-apache2")).to be_truthy + expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo.branch_exists?("chef-vendor-nginx")).to be_falsey end it "determines if a the branch not exists correctly without substring search" do - @cookbook_repo.should_receive(:shell_out!).twice.with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - @cookbook_repo.should_not be_branch_exists("chef-vendor-absent") - @cookbook_repo.should be_branch_exists("chef-vendor-absent-new") + expect(@cookbook_repo).to receive(:shell_out!).twice.with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).not_to be_branch_exists("chef-vendor-absent") + expect(@cookbook_repo).to be_branch_exists("chef-vendor-absent-new") end describe "when the pristine copy branch does not exist" do it "prepares for import by creating the pristine copy branch" do - @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - @cookbook_repo.should_receive(:shell_out!).with('git checkout -b chef-vendor-nginx', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with('git checkout -b chef-vendor-nginx', :cwd => @repo_path) @cookbook_repo.prepare_to_import("nginx") end end describe "when the pristine copy branch does exist" do it "prepares for import by checking out the pristine copy branch" do - @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - @cookbook_repo.should_receive(:shell_out!).with('git checkout chef-vendor-apache2', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with('git checkout chef-vendor-apache2', :cwd => @repo_path) @cookbook_repo.prepare_to_import("apache2") end end @@ -143,15 +143,15 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace("\n") - @cookbook_repo.stub(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) end it "shows no changes in the pristine copy" do - @cookbook_repo.updated?('apache2').should be_false + expect(@cookbook_repo.updated?('apache2')).to be_falsey end it "does nothing to finalize the updates" do - @cookbook_repo.finalize_updates_to('apache2', '1.2.3').should be_false + expect(@cookbook_repo.finalize_updates_to('apache2', '1.2.3')).to be_falsey end end @@ -159,18 +159,18 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace(" M cookbooks/apache2/recipes/default.rb\n") - @cookbook_repo.stub(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) end it "shows changes in the pristine copy" do - @cookbook_repo.updated?('apache2').should be_true + expect(@cookbook_repo.updated?('apache2')).to be_truthy end it "commits the changes to the repo and tags the commit" do - @cookbook_repo.should_receive(:shell_out!).with("git add apache2", :cwd => @repo_path) - @cookbook_repo.should_receive(:shell_out!).with("git commit -m \"Import apache2 version 1.2.3\" -- apache2", :cwd => @repo_path) - @cookbook_repo.should_receive(:shell_out!).with("git tag -f cookbook-site-imported-apache2-1.2.3", :cwd => @repo_path) - @cookbook_repo.finalize_updates_to("apache2", "1.2.3").should be_true + expect(@cookbook_repo).to receive(:shell_out!).with("git add apache2", :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git commit -m \"Import apache2 version 1.2.3\" -- apache2", :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git tag -f cookbook-site-imported-apache2-1.2.3", :cwd => @repo_path) + expect(@cookbook_repo.finalize_updates_to("apache2", "1.2.3")).to be_truthy end end @@ -180,7 +180,7 @@ DIRTY end it "resets to default state by checking out the default branch" do - @cookbook_repo.should_receive(:shell_out!).with('git checkout develop', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with('git checkout develop', :cwd => @repo_path) @cookbook_repo.reset_to_default_state end end |