spec/command/env_spec.rb in conjur-cli-4.16.0 vs spec/command/env_spec.rb in conjur-cli-4.17.0

- old
+ new

@@ -36,15 +36,29 @@ expect { invoke }.to raise_error /Options -c and --yaml can not be provided together/ end end end +shared_examples_for "accepts policy option" do |cmd, options| + before { # suspend all interaction with the environment + allow(Kernel).to receive(:system).and_return(true) + } + let(:stub_object) { double(obtain:{}, check:{}) } + describe_command "env:#{cmd} --policy foobar #{options}" do + it "uses .conjurenv file by default" do + expect(Conjur::Env).to receive(:new).with(file:".conjurenv", substitutions: { "$policy" => "foobar" }).and_return(stub_object) + invoke + end + end +end + describe Conjur::Command::Env, logged_in: true do let(:stub_env) { double() } describe ":check" do it_behaves_like "processes environment definition", "check", '' + it_behaves_like "accepts policy option", "check", '' describe_command "env:check" do before { expect(Conjur::Env).to receive(:new).and_return(stub_env) } describe "without api errors" do let(:stub_result) { { "a" => :available, "b"=> :available } } @@ -79,10 +93,11 @@ end end describe ":run" do it_behaves_like "processes environment definition", "run","-- extcmd" + it_behaves_like "accepts policy option", "run", '-- extcmd' describe_command "env:run" do it 'fails because of missing argument' do expect(Kernel).not_to receive(:system) expect { invoke }.to raise_error "External command with optional arguments should be provided" end @@ -117,9 +132,10 @@ allow(ERB).to receive(:new).and_return(double(result:'')) allow(Tempfile).to receive(:new).and_return(double(write: true, close: true, path: 'somepath')) allow(FileUtils).to receive(:copy).and_return(true) } it_behaves_like "processes environment definition", "template","config.erb" + it_behaves_like "accepts policy option", "template", 'config.erb' end describe_command "env:template" do it 'fails because of missing argument' do expect(Tempfile).not_to receive(:new) expect { invoke }.to raise_error "Location of readable ERB template should be provided"