Skip to content

Commit

Permalink
fix #verbose_list not appending a new line when items arg is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Sep 13, 2022
1 parent a023bb8 commit 1c9012c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exe/foreman_envsync
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions spec/unit/foreman_envsync_verbose_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 1c9012c

Please sign in to comment.