From 1c9012c5f7ca2e4501dc5865f5b8c8531101e8b3 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 13 Sep 2022 08:37:41 -0700 Subject: [PATCH] fix #verbose_list not appending a new line when items arg is empty --- exe/foreman_envsync | 2 +- spec/unit/foreman_envsync_verbose_list_spec.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/exe/foreman_envsync b/exe/foreman_envsync index 35cd23a..a68787a 100755 --- a/exe/foreman_envsync +++ b/exe/foreman_envsync @@ -31,9 +31,9 @@ def verbose_list(msg, items) return unless @options[:verbose] && !items.nil? printf(msg, items.count) + puts return if items.empty? - puts # do not attempt to sorry Array of Hashes if items.is_a?(Array) && items.first.is_a?(Hash) puts "#{YAML.dump(items)}\n" diff --git a/spec/unit/foreman_envsync_verbose_list_spec.rb b/spec/unit/foreman_envsync_verbose_list_spec.rb index 368971f..0ef36e0 100644 --- a/spec/unit/foreman_envsync_verbose_list_spec.rb +++ b/spec/unit/foreman_envsync_verbose_list_spec.rb @@ -7,7 +7,7 @@ before { @options = { verbose: true } } context "with array of hash" do - let(:aofh) { [{ a: 1 }, { b: 2 }] } + let(:items) { [{ a: 1 }, { b: 2 }] } let(:foo_output) do <<~FOO foo @@ -18,7 +18,18 @@ FOO end - it { expect { verbose_list("foo", aofh) }.to output(foo_output).to_stdout } + it { expect { verbose_list("foo", items) }.to output(foo_output).to_stdout } + end + + context "with empty array" do + let(:items) { [] } + let(:foo_output) do + <<~FOO + foo + FOO + end + + it { expect { verbose_list("foo", items) }.to output(foo_output).to_stdout } end end end