Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow registering OutputFormats without file extension #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ronin/core/output_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
28 changes: 28 additions & 0 deletions spec/output_formats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down