Skip to content

Commit

Permalink
Merge pull request #633 from mobilutz/ll-create-report-dir
Browse files Browse the repository at this point in the history
Create output dir if not existent
  • Loading branch information
xtreme-shane-lattanzio authored Oct 24, 2019
2 parents 1d34277 + d45be01 commit 9766c6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/license_finder/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def aggregate_paths
end

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

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 9766c6f

Please sign in to comment.