spec/unit/action/runner_spec.rb in r10k-3.1.1 vs spec/unit/action/runner_spec.rb in r10k-3.2.0
- old
+ new
@@ -23,10 +23,14 @@
end
end
subject(:runner) { described_class.new({:opts => :yep}, %w[args yes], action_class) }
+ before(:each) do
+ expect(runner.logger).not_to receive(:error)
+ end
+
describe "instantiating the wrapped class" do
it "creates an instance of the class" do
expect(runner.instance).to be_a_kind_of action_class
end
@@ -57,9 +61,100 @@
runner.call
end
it "returns the result of the wrapped class #call method" do
expect(runner.call).to eq %w[ARGS YES]
+ end
+ end
+
+ describe "configuring settings" do
+ subject(:runner) { described_class.new(options, %w[args yes], action_class) }
+
+ let(:global_settings) { R10K::Settings.global_settings }
+
+ before(:each) do
+ expect(R10K::Settings).to receive(:global_settings).and_return(global_settings)
+ allow(File).to receive(:executable?).and_return(true)
+ end
+
+ opts = {
+ cachedir: nil,
+ puppet_path: :deploy,
+ generate_types: :deploy,
+ }
+
+ opts.each do |opt, conf_path|
+ context "with #{opt} config setting" do
+ let(:options) { { config: "spec/fixtures/unit/action/r10k_#{opt}.yaml" } }
+
+ context "when not overridden" do
+ it "uses the config value" do
+ override = { "#{opt}": "/config_#{opt}" }
+ overrides = if conf_path.nil?
+ override
+ else
+ { "#{conf_path}": override }
+ end
+ expect(global_settings).to receive(:evaluate).with(overrides).and_call_original
+ runner.call
+ end
+ end
+
+ context "when overridden" do
+ let(:options) { super().merge("#{opt.to_s.sub('_','-')}": "/overridden_#{opt}") }
+
+ it "uses the overridden value" do
+ override = { "#{opt}": "/overridden_#{opt}" }
+ overrides = if conf_path.nil?
+ override
+ else
+ { "#{conf_path}": override }
+ end
+ expect(global_settings).to receive(:evaluate).with(overrides).and_call_original
+ runner.call
+ end
+ end
+ end
+
+ context "with complete config" do
+ let(:options) { { config: "spec/fixtures/unit/action/r10k.yaml" } }
+ let(:config) do
+ config = {}
+ opts.each do |o, path|
+ if path.nil?
+ config[o] = "/config_#{o}"
+ else
+ config[path] ||= {}
+ config[path][o] = "/config_#{o}"
+ end
+ end
+ config
+ end
+
+ context "when not overridden" do
+ it "uses the config value" do
+ expect(global_settings).to receive(:evaluate).with(config).and_call_original
+ runner.call
+ end
+ end
+
+ context "when overridden" do
+ let(:options) {
+ super().merge("#{opt.to_s.sub('_','-')}": "/overridden_#{opt}")
+ }
+
+ it "uses the overridden value" do
+ with_overrides = config
+ if conf_path.nil?
+ with_overrides[opt] = "/overridden_#{opt}"
+ else
+ with_overrides[conf_path][opt] = "/overridden_#{opt}"
+ end
+ expect(global_settings).to receive(:evaluate).with(with_overrides).and_call_original
+ runner.call
+ end
+ end
+ end
end
end
describe "configuring logging" do
it "sets the log level if :loglevel is provided" do