diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-09-30 11:16:31 -0700 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-07 15:34:34 -0700 |
commit | 25104da3b9be7545ca8911cb0f11a42f524989a3 (patch) | |
tree | bd279b75a00e1b0e27cbae7a2995b372d0242e31 /spec/unit/mixin/homebrew_user_spec.rb | |
parent | d4c52ac9722d67829e3d1393ba0b9cc59eb003ed (diff) | |
download | chef-25104da3b9be7545ca8911cb0f11a42f524989a3.tar.gz |
Moving documentation to a more logical place. Also no longer dis-allowing users from running brew as root.
Diffstat (limited to 'spec/unit/mixin/homebrew_user_spec.rb')
-rw-r--r-- | spec/unit/mixin/homebrew_user_spec.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/spec/unit/mixin/homebrew_user_spec.rb b/spec/unit/mixin/homebrew_user_spec.rb index a27a6a0460..7af04f0958 100644 --- a/spec/unit/mixin/homebrew_user_spec.rb +++ b/spec/unit/mixin/homebrew_user_spec.rb @@ -47,7 +47,7 @@ describe Chef::Mixin::HomebrewUser do end - describe 'when the homebrew user is not provided' do + shared_examples "successfully find executable" do let(:user) { nil } let(:brew_owner) { 2001 } let(:default_brew_path) { '/usr/local/bin/brew' } @@ -57,6 +57,10 @@ describe Chef::Mixin::HomebrewUser do d } + before do + expect(Etc).to receive(:getpwuid).with(brew_owner).and_return(OpenStruct.new(:name => "name")) + end + it 'returns the owner of the brew executable when it is at a default location' do expect(File).to receive(:exist?).with(default_brew_path).and_return(true) expect(File).to receive(:stat).with(default_brew_path).and_return(stat_double) @@ -69,6 +73,11 @@ describe Chef::Mixin::HomebrewUser do expect(File).to receive(:stat).with("/foo").and_return(stat_double) expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner) end + end + + describe 'when the homebrew user is not provided' do + + include_examples "successfully find executable" it 'raises an error if no executable is found' do expect(File).to receive(:exist?).with(default_brew_path).and_return(false) @@ -76,13 +85,10 @@ describe Chef::Mixin::HomebrewUser do expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewOwner) end - describe "the executable is owned by root" do + context "the executable is owned by root" do let(:brew_owner) { 0 } - - it 'raises an error' do - expect(File).to receive(:exist?).with(default_brew_path).and_return(true) - expect(File).to receive(:stat).with(default_brew_path).and_return(stat_double) - expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::HomebrewOwnerIsRoot) + include_examples "successfully find executable" do + let(:brew_owner) { 0 } end end |