Skip to content

Commit

Permalink
Create output dir if not existant
Browse files Browse the repository at this point in the history
  • Loading branch information
mobilutz committed Oct 24, 2019
1 parent 01c69ca commit 97ab9a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/license_finder/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def aggregate_paths
end

def save_report(content, file_name)
require 'fileutils'
dir = File.dirname(file_name)
unless Dir.exist?(dir)
FileUtils.mkdir_p(dir)
end

File.open(file_name, 'w') do |f|
f.write(content)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/license_finder/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ def report
subject.report
end
end

context 'when folder does not exist, it is being created' do
let(:save) { 'output/subfolder/license_report.txt' }

after do
# cleanup to remove the created directory again
FileUtils.rm_rf('output')
end

it 'calls `FileUtils` which creates the directory' do
subject.options = { 'save' => save }
expect(FileUtils).to receive(:mkdir_p).with('output/subfolder').and_call_original

subject.report
end
end
end

context 'when the --save option is not passed' do
Expand Down

0 comments on commit 97ab9a0

Please sign in to comment.