diff --git a/lib/ronin/core/output_formats.rb b/lib/ronin/core/output_formats.rb index 4ba37e6..52f5700 100644 --- a/lib/ronin/core/output_formats.rb +++ b/lib/ronin/core/output_formats.rb @@ -65,9 +65,9 @@ def file_exts # # Registers a new output format. # - def register(name,ext,output_format) + def register(name,ext=nil,output_format) formats[name] = output_format - file_exts[ext] = output_format + file_exts[ext] = output_format if ext end # diff --git a/spec/output_formats_spec.rb b/spec/output_formats_spec.rb index f5ca5a4..1aaf623 100644 --- a/spec/output_formats_spec.rb +++ b/spec/output_formats_spec.rb @@ -15,6 +15,14 @@ module OutputFormats register :json, '.json', JSON register :ndjson, '.ndjson', NDJSON end + + class NoExtOutputFormat < Ronin::Core::OutputFormats::OutputFile; end + + module NoExtOutputFormats + include Ronin::Core::OutputFormats + + register :no_ext, NoExtOutputFormat + end end subject { TestOutputFormats::EmptyOutputFormats } @@ -66,6 +74,14 @@ module OutputFormats ) end end + + context "when output formats without extension have been registered" do + subject { TestOutputFormats::NoExtOutputFormats } + + it "must return an empty Hash" do + expect(subject.file_exts).to eq({}) + end + end end describe ".register" do @@ -78,6 +94,18 @@ module OutputFormats it "must register the output format in #file_exts with the given ext" do expect(subject.file_exts['.txt']).to be(described_class::TXT) end + + context "without file extension" do + subject { TestOutputFormats::NoExtOutputFormats } + + it "must register the output format in #formats with the given name" do + expect(subject.formats[:no_ext]).to be(TestOutputFormats::NoExtOutputFormat) + end + + it "must not register the output format in #file_exts" do + expect(subject.file_exts).to eq({}) + end + end end describe ".infer_from" do