Skip to content

Commit 36c9c20

Browse files
author
Kevin Paulisse
committed
Require array input to printer()
1 parent 7b1cff3 commit 36c9c20

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/octocatalog-diff/cli/printer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ def initialize(options, logger)
1919
# The method to call externally, passing in diffs. This takes the appropriate action
2020
# based on options, which is either to write the result into an output file, or print
2121
# the result on STDOUT. Does not return anything.
22-
# @param diffs [OctocatalogDiff::CatalogDiff::Differ] Difference array
22+
# @param diffs [Array<Diffs>] Array of differences
2323
# @param from_dir [String] Directory in which "from" catalog was compiled
2424
# @param to_dir [String] Directory in which "to" catalog was compiled
2525
def printer(diffs, from_dir = nil, to_dir = nil)
26+
unless diffs.is_a?(Array)
27+
raise ArgumentError, "printer() expects an array, not #{diffs.class}"
28+
end
2629
display_opts = @options.merge(compilation_from_dir: from_dir, compilation_to_dir: to_dir)
2730
diff_text = OctocatalogDiff::CatalogDiff::Display.output(diffs, display_opts, @logger)
2831
if @options[:output_file].nil?

spec/octocatalog-diff/tests/cli/printer_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
@diff = JSON.parse(File.read(OctocatalogDiff::Spec.fixture_path('diffs/catalog-1-vs-catalog-2.json')))
1515
end
1616

17+
it 'should raise an ArgumentError when called with something other than an array' do
18+
testobj = described_class.new(nil, nil)
19+
expect do
20+
testobj.printer(:foo)
21+
end.to raise_error(ArgumentError, 'printer() expects an array, not Symbol')
22+
end
23+
1724
it 'should write to a file when options output_file is specified' do
1825
begin
1926
# Set up the tempfile to output to.

0 commit comments

Comments
 (0)