diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-02-07 14:13:42 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-02-07 14:13:42 -0800 |
commit | 794aa7b565355b0a0c9b7f765048c28510437d0c (patch) | |
tree | efb7085b6a6575a3b1b6212abeb653ff030fd92e /spec | |
parent | 2f67ecb8e69ac10956145c64c612537b82ddd971 (diff) | |
download | chef-794aa7b565355b0a0c9b7f765048c28510437d0c.tar.gz |
add a couple where-with-a-block tests
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/mixin/which.rb | 26 | ||||
-rw-r--r-- | spec/unit/util/selinux_spec.rb | 2 |
2 files changed, 20 insertions, 8 deletions
diff --git a/spec/unit/mixin/which.rb b/spec/unit/mixin/which.rb index 179251f86c..f9f1969e38 100644 --- a/spec/unit/mixin/which.rb +++ b/spec/unit/mixin/which.rb @@ -1,5 +1,4 @@ # -# Author:: Seth Chisamore (<schisamo@chef.io>) # Copyright:: Copyright 2011-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # @@ -26,7 +25,7 @@ describe Chef::Mixin::Which do let(:test) { TestClass.new } - def self.test_which(description, *args, finds: nil, others: nil, directory: false, &block) + def self.test_which(description, *args, finds: nil, others: [], directory: false, &block) it description do # stub the ENV['PATH'] expect(test).to receive(:env_path).and_return(["/dir1", "/dir2" ].join(File::PATH_SEPARATOR)) @@ -42,10 +41,8 @@ describe Chef::Mixin::Which do expect(File).to receive(:directory?).with(finds).and_return(true) if finds && directory # allow for stubbing other paths to exist that we should not find - if others - others.each do |other| - allow(File).to receive(:executable?).with(other).and_return(true) - end + others.each do |other| + allow(File).to receive(:executable?).with(other).and_return(true) end # setup the actual expectation on the return value @@ -101,7 +98,7 @@ describe Chef::Mixin::Which do end end - def self.test_where(description, *args, finds: [], &block) + def self.test_where(description, *args, finds: [], others: [], &block) it description do # stub the ENV['PATH'] expect(test).to receive(:env_path).and_return(["/dir1", "/dir2" ].join(File::PATH_SEPARATOR)) @@ -110,6 +107,11 @@ describe Chef::Mixin::Which do allow(File).to receive(:executable?).and_return(false) allow(File).to receive(:directory?).and_return(false) + # allow for stubbing other paths to exist that we should not return + others.each do |other| + allow(File).to receive(:executable?).with(other).and_return(true) + end + # stub the expectation finds.each do |path| expect(File).to receive(:executable?).with(path).and_return(true) @@ -144,5 +146,15 @@ describe Chef::Mixin::Which do test_where("finds foo2 first if they're reversed", "foo2", "foo1", finds: [ "/dir1/foo2", "/dir1/foo1" ]) end + + context "with a block do" do + test_where("finds foo1 and foo2 if they exist and the block is true", "foo1", "foo2", finds: [ "/dir1/foo2", "/dir2/foo2" ]) do + true + end + + test_where("does not finds foo1 and foo2 if they exist and the block is false", "foo1", "foo2", others: [ "/dir1/foo2", "/dir2/foo2" ]) do + false + end + end end end diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb index 69d1ccdb1f..751092bc9a 100644 --- a/spec/unit/util/selinux_spec.rb +++ b/spec/unit/util/selinux_spec.rb @@ -1,6 +1,6 @@ # # Author:: Serdar Sutay (<serdar@chef.io>) -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); |