summaryrefslogtreecommitdiff
path: root/spec/unit/provider/git_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/provider/git_spec.rb')
-rw-r--r--spec/unit/provider/git_spec.rb344
1 files changed, 172 insertions, 172 deletions
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index 02d155efbd..bfbf531389 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -21,7 +21,7 @@ require 'spec_helper'
describe Chef::Provider::Git do
before(:each) do
- STDOUT.stub(:tty?).and_return(true)
+ allow(STDOUT).to receive(:tty?).and_return(true)
Chef::Log.level = :info
@current_resource = Chef::Resource::Git.new("web2.0 app")
@@ -47,36 +47,36 @@ describe Chef::Provider::Git do
end
it "sets the current revision to nil if the deploy dir does not exist" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
- @provider.find_current_revision.should be_nil
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
+ expect(@provider.find_current_revision).to be_nil
end
it "determines the current revision when there is one" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
@stdout = "9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13\n"
- @provider.should_receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.find_current_revision.should eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13")
+ expect(@provider).to receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.find_current_revision).to eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13")
end
it "gives the current revision as nil when there is no current revision" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
@stderr = "fatal: Not a git repository (or any of the parent directories): .git"
@stdout = ""
- @provider.should_receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr))
- @provider.find_current_revision.should be_nil
+ expect(@provider).to receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr))
+ expect(@provider.find_current_revision).to be_nil
end
end
it "creates a current_resource with the currently deployed revision when a clone exists in the destination dir" do
- @provider.stub(:find_current_revision).and_return("681c9802d1c62a45b490786c18f0b8216b309440")
+ allow(@provider).to receive(:find_current_revision).and_return("681c9802d1c62a45b490786c18f0b8216b309440")
@provider.load_current_resource
- @provider.current_resource.name.should eql(@resource.name)
- @provider.current_resource.revision.should eql("681c9802d1c62a45b490786c18f0b8216b309440")
+ expect(@provider.current_resource.name).to eql(@resource.name)
+ expect(@provider.current_resource.revision).to eql("681c9802d1c62a45b490786c18f0b8216b309440")
end
it "keeps the node and resource passed to it on initialize" do
- @provider.node.should equal(@node)
- @provider.new_resource.should equal(@resource)
+ expect(@provider.node).to equal(@node)
+ expect(@provider.new_resource).to equal(@resource)
end
context "resolving revisions to a SHA" do
@@ -86,15 +86,15 @@ describe Chef::Provider::Git do
end
it "returns resource.revision as is if revision is already a full SHA" do
- @provider.target_revision.should eql("d35af14d41ae22b19da05d7d03a0bafc321b244c")
+ expect(@provider.target_revision).to eql("d35af14d41ae22b19da05d7d03a0bafc321b244c")
end
it "converts resource.revision from a tag to a SHA" do
@resource.revision "v1.0"
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from an annotated tag to the tagged SHA (not SHA of tag)" do
@@ -102,8 +102,8 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0^{}\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("663c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from a tag to a SHA using an exact match" do
@@ -111,8 +111,8 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/releases/v1.0\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from a tag to a SHA, matching tags first, then heads" do
@@ -120,8 +120,8 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("663c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from a tag to a SHA, matching heads if no tags match" do
@@ -129,8 +129,8 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.1\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from a tag to a SHA, matching tags first, then heads, then revision" do
@@ -139,8 +139,8 @@ describe Chef::Provider::Git do
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" +
"805c22a5e41f5ae3193460cca044ed1435029f53\trefs/pulls/v1.0\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"refs/pulls/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("805c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"refs/pulls/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("805c22a5e41f5ae3193460cca044ed1435029f53")
end
it "converts resource.revision from a tag to a SHA, using full path if provided" do
@@ -148,40 +148,40 @@ describe Chef::Provider::Git do
@stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" +
"663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" +
"503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n")
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"refs/heads/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"refs/heads/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53")
end
it "raises an invalid remote reference error if you try to deploy from ``origin'' and assertions are run" do
@resource.revision "origin/"
@provider.action = :checkout
@provider.define_resource_requirements
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- lambda {@provider.process_resource_requirements}.should raise_error(Chef::Exceptions::InvalidRemoteGitReference)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ expect {@provider.process_resource_requirements}.to raise_error(Chef::Exceptions::InvalidRemoteGitReference)
end
it "raises an unresolvable git reference error if the revision can't be resolved to any revision and assertions are run" do
@resource.revision "FAIL, that's the revision I want"
@provider.action = :checkout
- @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n"))
+ expect(@provider).to receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n"))
@provider.define_resource_requirements
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::UnresolvableGitReference)
+ expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::UnresolvableGitReference)
end
it "does not raise an error if the revision can't be resolved when assertions are not run" do
@resource.revision "FAIL, that's the revision I want"
- @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n"))
- @provider.target_revision.should == nil
+ expect(@provider).to receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n"))
+ expect(@provider.target_revision).to eq(nil)
end
it "does not raise an error when the revision is valid and assertions are run." do
@resource.revision "0.8-alpha"
@stdout = "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n"
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
@provider.action = :checkout
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
@provider.define_resource_requirements
- lambda { @provider.process_resource_requirements }.should_not raise_error
+ expect { @provider.process_resource_requirements }.not_to raise_error
end
it "gives the latest HEAD revision SHA if nothing is specified" do
@@ -202,13 +202,13 @@ b7d19519a1c15f1c1a324e2683bd728b6198ce5a\trefs/tags/0.7.8^{}
ebc1b392fe7e8f0fbabc305c299b4d365d2b4d9b\trefs/tags/chef-server-package
SHAS
@resource.revision ''
- @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
- @provider.target_revision.should eql("28af684d8460ba4793eda3e7ac238c864a5d029a")
+ expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout))
+ expect(@provider.target_revision).to eql("28af684d8460ba4793eda3e7ac238c864a5d029a")
end
end
it "responds to :revision_slug as an alias for target_revision" do
- @provider.should respond_to(:revision_slug)
+ expect(@provider).to respond_to(:revision_slug)
end
context "with an ssh wrapper" do
@@ -225,11 +225,11 @@ SHAS
before do
@resource.user deploy_user
@resource.ssh_wrapper wrapper
- Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
+ allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
end
context "without a timeout set" do
it "clones a repo with default git options" do
- @provider.should_receive(:shell_out!).with(expected_cmd, default_options)
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, default_options)
@provider.clone
end
end
@@ -237,7 +237,7 @@ SHAS
let (:seconds) { 10 }
before { @resource.timeout(seconds) }
it "clones a repo with amended git options" do
- @provider.should_receive(:shell_out!).with(expected_cmd, default_options.merge(:timeout => seconds))
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, default_options.merge(:timeout => seconds))
@provider.clone
end
end
@@ -257,7 +257,7 @@ SHAS
end
before { @resource.environment(override_home) }
it "clones a repo with amended git options with specific home" do
- @provider.should_receive(:shell_out!).with(expected_cmd, overrided_options)
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, overrided_options)
@provider.clone
end
end
@@ -265,11 +265,11 @@ SHAS
it "runs a clone command with escaped destination" do
@resource.user "deployNinja"
- Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
+ allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja"))
@resource.destination "/Application Support/with/space"
@resource.ssh_wrapper "do_it_this_way.sh"
expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\""
- @provider.should_receive(:shell_out!).with(expected_cmd, :user => "deployNinja",
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :user => "deployNinja",
:environment =>{"GIT_SSH"=>"do_it_this_way.sh",
"HOME" => "/home/deployNinja"},
:log_tag => "git[web2.0 app]")
@@ -280,10 +280,10 @@ SHAS
@resource.depth 5
expected_cmd = "git clone --depth 5 \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
version_response = double('shell_out')
- version_response.stub(:stdout) { 'git version 1.7.9' }
- @provider.should_receive(:shell_out!).with("git --version",
+ allow(version_response).to receive(:stdout) { 'git version 1.7.9' }
+ expect(@provider).to receive(:shell_out!).with("git --version",
:log_tag => "git[web2.0 app]").and_return(version_response)
- @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
@provider.clone
end
@@ -291,24 +291,24 @@ SHAS
@resource.depth 5
expected_cmd = "git clone --depth 5 --no-single-branch \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
version_response = double('shell_out')
- version_response.stub(:stdout) { 'git version 1.7.10' }
- @provider.should_receive(:shell_out!).with("git --version",
+ allow(version_response).to receive(:stdout) { 'git version 1.7.10' }
+ expect(@provider).to receive(:shell_out!).with("git --version",
:log_tag => "git[web2.0 app]").and_return(version_response)
- @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
@provider.clone
end
it "compiles a clone command with a remote other than ``origin''" do
@resource.remote "opscode"
expected_cmd = "git clone -o opscode \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\""
- @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]")
@provider.clone
end
it "runs a checkout command with default options" do
- @provider.should_receive(:shell_out!).with('git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c', :cwd => "/my/deploy/dir",
+ expect(@provider).to receive(:shell_out!).with('git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c', :cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]").ordered
- @provider.should_receive(:shell_out!).with('git checkout deploy', :cwd => "/my/deploy/dir",
+ expect(@provider).to receive(:shell_out!).with('git checkout deploy', :cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]").ordered
@provider.checkout
end
@@ -316,32 +316,32 @@ SHAS
it "runs an enable_submodule command" do
@resource.enable_submodules true
expected_cmd = "git submodule sync"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
expected_cmd = "git submodule update --init --recursive"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@provider.enable_submodules
end
it "does nothing for enable_submodules if resource.enable_submodules #=> false" do
- @provider.should_not_receive(:shell_out!)
+ expect(@provider).not_to receive(:shell_out!)
@provider.enable_submodules
end
it "runs a sync command with default options" do
- @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
+ expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@provider.fetch_updates
end
it "runs a sync command with the user and group specified in the resource" do
@resource.user("whois")
- Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
+ allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
@resource.group("thisis")
- @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
+ expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
+ expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
:user => "whois", :group => "thisis",
:log_tag => "git[web2.0 app]",
:environment=>{"HOME"=>"/home/whois"})
@@ -350,17 +350,17 @@ SHAS
it "configures remote tracking branches when remote is ``origin''" do
@resource.remote "origin"
- @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
+ expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
fetch_command = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@provider.fetch_updates
end
it "configures remote tracking branches when remote is not ``origin''" do
@resource.remote "opscode"
- @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
+ expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository)
fetch_command = "git fetch opscode && git fetch opscode --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c"
- @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
+ expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]")
@provider.fetch_updates
end
@@ -368,14 +368,14 @@ SHAS
it "checks if a remote with this name already exists" do
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 1 }
+ allow(command_response).to receive(:exitstatus) { 1 }
expected_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(expected_command,
+ expect(@provider).to receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:returns => [0,1,2]).and_return(command_response)
add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(add_remote_command,
+ expect(@provider).to receive(:shell_out!).with(add_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
@@ -384,11 +384,11 @@ SHAS
it "runs the config with the user and group specified in the resource" do
@resource.user("whois")
@resource.group("thisis")
- Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
+ allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois"))
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 1 }
+ allow(command_response).to receive(:exitstatus) { 1 }
expected_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(expected_command,
+ expect(@provider).to receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:user => "whois",
@@ -396,7 +396,7 @@ SHAS
:environment=>{"HOME"=>"/home/whois"},
:returns => [0,1,2]).and_return(command_response)
add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(add_remote_command,
+ expect(@provider).to receive(:shell_out!).with(add_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:user => "whois",
@@ -408,14 +408,14 @@ SHAS
describe "when a remote with a given name hasn't been configured yet" do
it "adds a new remote " do
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 1 }
+ allow(command_response).to receive(:exitstatus) { 1 }
check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
+ expect(@provider).to receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:returns => [0,1,2]).and_return(command_response)
expected_command = "git remote add #{@resource.remote} #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
+ expect(@provider).to receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
@@ -425,15 +425,15 @@ SHAS
describe "when a remote with a given name has already been configured" do
it "updates remote url when the url is different" do
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 0 }
- command_response.stub(:stdout) { "some_other_url" }
+ allow(command_response).to receive(:exitstatus) { 0 }
+ allow(command_response).to receive(:stdout) { "some_other_url" }
check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
+ expect(@provider).to receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:returns => [0,1,2]).and_return(command_response)
expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
+ expect(@provider).to receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
@@ -441,15 +441,15 @@ SHAS
it "doesn't update remote url when the url is the same" do
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 0 }
- command_response.stub(:stdout) { @resource.repository }
+ allow(command_response).to receive(:exitstatus) { 0 }
+ allow(command_response).to receive(:stdout) { @resource.repository }
check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
+ expect(@provider).to receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:returns => [0,1,2]).and_return(command_response)
unexpected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_not_receive(:shell_out!).with(unexpected_command,
+ expect(@provider).not_to receive(:shell_out!).with(unexpected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
@@ -457,14 +457,14 @@ SHAS
it "resets remote url when it has multiple values" do
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 2 }
+ allow(command_response).to receive(:exitstatus) { 2 }
check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
+ expect(@provider).to receive(:shell_out!).with(check_remote_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]",
:returns => [0,1,2]).and_return(command_response)
expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
+ expect(@provider).to receive(:shell_out!).with(expected_command,
:cwd => "/my/deploy/dir",
:log_tag => "git[web2.0 app]")
@provider.setup_remote_tracking_branches(@resource.remote, @resource.repository)
@@ -473,20 +473,20 @@ SHAS
end
it "raises an error if the git clone command would fail because the enclosing directory doesn't exist" do
- @provider.stub(:shell_out!)
- lambda {@provider.run_action(:sync)}.should raise_error(Chef::Exceptions::MissingParentDirectory)
+ allow(@provider).to receive(:shell_out!)
+ expect {@provider.run_action(:sync)}.to raise_error(Chef::Exceptions::MissingParentDirectory)
end
it "does a checkout by cloning the repo and then enabling submodules" do
# will be invoked in load_current_resource
- ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false)
-
- ::File.stub(:exist?).with("/my/deploy/dir").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..'])
- @provider.should_receive(:clone)
- @provider.should_receive(:checkout)
- @provider.should_receive(:enable_submodules)
+ allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
+
+ allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..'])
+ expect(@provider).to receive(:clone)
+ expect(@provider).to receive(:checkout)
+ expect(@provider).to receive(:enable_submodules)
@provider.run_action(:checkout)
# Even though an actual run will cause an update to occur, the fact that we've stubbed out
# the actions above will prevent updates from registering
@@ -495,119 +495,119 @@ SHAS
it "does not call checkout if enable_checkout is false" do
# will be invoked in load_current_resource
- ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false)
+ allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
- ::File.stub(:exist?).with("/my/deploy/dir").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..'])
+ allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..'])
@resource.enable_checkout false
- @provider.should_receive(:clone)
- @provider.should_not_receive(:checkout)
- @provider.should_receive(:enable_submodules)
+ expect(@provider).to receive(:clone)
+ expect(@provider).not_to receive(:checkout)
+ expect(@provider).to receive(:enable_submodules)
@provider.run_action(:checkout)
end
# REGRESSION TEST: on some OSes, the entries from an empty directory will be listed as
# ['..', '.'] but this shouldn't change the behavior
it "does a checkout by cloning the repo and then enabling submodules when the directory entries are listed as %w{.. .}" do
- ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false)
- ::File.stub(:exist?).with("/my/deploy/dir").and_return(false)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['..','.'])
- @provider.should_receive(:clone)
- @provider.should_receive(:checkout)
- @provider.should_receive(:enable_submodules)
- @provider.should_receive(:add_remotes)
+ allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
+ allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(false)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['..','.'])
+ expect(@provider).to receive(:clone)
+ expect(@provider).to receive(:checkout)
+ expect(@provider).to receive(:enable_submodules)
+ expect(@provider).to receive(:add_remotes)
@provider.run_action(:checkout)
# @resource.should be_updated
end
it "should not checkout if the destination exists or is a non empty directory" do
# will be invoked in load_current_resource
- ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false)
-
- ::File.stub(:exist?).with("/my/deploy/dir").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar'])
- @provider.should_not_receive(:clone)
- @provider.should_not_receive(:checkout)
- @provider.should_not_receive(:enable_submodules)
- @provider.should_not_receive(:add_remotes)
+ allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false)
+
+ allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar'])
+ expect(@provider).not_to receive(:clone)
+ expect(@provider).not_to receive(:checkout)
+ expect(@provider).not_to receive(:enable_submodules)
+ expect(@provider).not_to receive(:add_remotes)
@provider.run_action(:checkout)
- @resource.should_not be_updated
+ expect(@resource).not_to be_updated
end
it "syncs the code by updating the source when the repo has already been checked out" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- @provider.should_receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
- @provider.should_not_receive(:fetch_updates)
- @provider.should_receive(:add_remotes)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ expect(@provider).to receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
+ expect(@provider).not_to receive(:fetch_updates)
+ expect(@provider).to receive(:add_remotes)
@provider.run_action(:sync)
- @resource.should_not be_updated
+ expect(@resource).not_to be_updated
end
it "marks the resource as updated when the repo is updated and gets a new version" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
# invoked twice - first time from load_current_resource
- @provider.should_receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
- @provider.stub(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a')
- @provider.should_receive(:fetch_updates)
- @provider.should_receive(:enable_submodules)
- @provider.should_receive(:add_remotes)
+ expect(@provider).to receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
+ allow(@provider).to receive(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a')
+ expect(@provider).to receive(:fetch_updates)
+ expect(@provider).to receive(:enable_submodules)
+ expect(@provider).to receive(:add_remotes)
@provider.run_action(:sync)
# @resource.should be_updated
end
it "does not fetch any updates if the remote revision matches the current revision" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- @provider.stub(:find_current_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
- @provider.stub(:target_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
- @provider.should_not_receive(:fetch_updates)
- @provider.should_receive(:add_remotes)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(@provider).to receive(:find_current_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
+ allow(@provider).to receive(:target_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c')
+ expect(@provider).not_to receive(:fetch_updates)
+ expect(@provider).to receive(:add_remotes)
@provider.run_action(:sync)
- @resource.should_not be_updated
+ expect(@resource).not_to be_updated
end
it "clones the repo instead of fetching it if the deploy directory doesn't exist" do
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false)
- @provider.should_receive(:action_checkout)
- @provider.should_not_receive(:shell_out!)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false)
+ expect(@provider).to receive(:action_checkout)
+ expect(@provider).not_to receive(:shell_out!)
@provider.run_action(:sync)
# @resource.should be_updated
end
it "clones the repo instead of fetching updates if the deploy directory is empty" do
- ::File.should_receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false)
- ::File.stub(:directory?).with("/my/deploy").and_return(true)
- ::File.stub(:directory?).with("/my/deploy/dir").and_return(true)
- @provider.stub(:sync_command).and_return("huzzah!")
- @provider.should_receive(:action_checkout)
- @provider.should_not_receive(:shell_out!).with("huzzah!", :cwd => "/my/deploy/dir")
+ expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false)
+ allow(::File).to receive(:directory?).with("/my/deploy").and_return(true)
+ allow(::File).to receive(:directory?).with("/my/deploy/dir").and_return(true)
+ allow(@provider).to receive(:sync_command).and_return("huzzah!")
+ expect(@provider).to receive(:action_checkout)
+ expect(@provider).not_to receive(:shell_out!).with("huzzah!", :cwd => "/my/deploy/dir")
@provider.run_action(:sync)
#@resource.should be_updated
end
it "does an export by cloning the repo then removing the .git directory" do
- @provider.should_receive(:action_checkout)
- FileUtils.should_receive(:rm_rf).with(@resource.destination + "/.git")
+ expect(@provider).to receive(:action_checkout)
+ expect(FileUtils).to receive(:rm_rf).with(@resource.destination + "/.git")
@provider.run_action(:export)
- @resource.should be_updated
+ expect(@resource).to be_updated
end
describe "calling add_remotes" do
it "adds a new remote for each entry in additional remotes hash" do
@resource.additional_remotes({:opscode => "opscode_repo_url",
:another_repo => "some_other_repo_url"})
- STDOUT.stub(:tty?).and_return(false)
+ allow(STDOUT).to receive(:tty?).and_return(false)
command_response = double('shell_out')
- command_response.stub(:exitstatus) { 0 }
+ allow(command_response).to receive(:exitstatus) { 0 }
@resource.additional_remotes.each_pair do |remote_name, remote_url|
- @provider.should_receive(:setup_remote_tracking_branches).with(remote_name, remote_url)
+ expect(@provider).to receive(:setup_remote_tracking_branches).with(remote_name, remote_url)
end
@provider.add_remotes
end
@@ -620,22 +620,22 @@ SHAS
describe "when check remote command returns with status 2" do
it "returns true" do
- @command_response.stub(:exitstatus) { 2 }
- @provider.multiple_remotes?(@command_response).should be_true
+ allow(@command_response).to receive(:exitstatus) { 2 }
+ expect(@provider.multiple_remotes?(@command_response)).to be_true
end
end
describe "when check remote command returns with status 0" do
it "returns false" do
- @command_response.stub(:exitstatus) { 0 }
- @provider.multiple_remotes?(@command_response).should be_false
+ allow(@command_response).to receive(:exitstatus) { 0 }
+ expect(@provider.multiple_remotes?(@command_response)).to be_false
end
end
describe "when check remote command returns with status 0" do
it "returns false" do
- @command_response.stub(:exitstatus) { 1 }
- @provider.multiple_remotes?(@command_response).should be_false
+ allow(@command_response).to receive(:exitstatus) { 1 }
+ expect(@provider.multiple_remotes?(@command_response)).to be_false
end
end
end
@@ -647,17 +647,17 @@ SHAS
describe "when output of the check remote command matches the repository url" do
it "returns true" do
- @command_response.stub(:exitstatus) { 0 }
- @command_response.stub(:stdout) { @resource.repository }
- @provider.remote_matches?(@resource.repository, @command_response).should be_true
+ allow(@command_response).to receive(:exitstatus) { 0 }
+ allow(@command_response).to receive(:stdout) { @resource.repository }
+ expect(@provider.remote_matches?(@resource.repository, @command_response)).to be_true
end
end
describe "when output of the check remote command doesn't match the repository url" do
it "returns false" do
- @command_response.stub(:exitstatus) { 0 }
- @command_response.stub(:stdout) { @resource.repository + "test" }
- @provider.remote_matches?(@resource.repository, @command_response).should be_false
+ allow(@command_response).to receive(:exitstatus) { 0 }
+ allow(@command_response).to receive(:stdout) { @resource.repository + "test" }
+ expect(@provider.remote_matches?(@resource.repository, @command_response)).to be_false
end
end
end