Skip to content

Commit

Permalink
Merge pull request #927 from presidentbeef/make_path_to_report
Browse files Browse the repository at this point in the history
Make path to report
  • Loading branch information
presidentbeef committed Aug 24, 2016
2 parents 2cec84a + 76e3564 commit 3b2a8cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/brakeman.rb
Expand Up @@ -362,7 +362,14 @@ def self.scan options
end

def self.write_report_to_files tracker, output_files
require 'fileutils'

output_files.each_with_index do |output_file, idx|
dir = File.dirname(output_file)
unless Dir.exist? dir
FileUtils.mkdir_p(dir)
end

File.open output_file, "w" do |f|
f.write tracker.report.format(tracker.options[:output_formats][idx])
end
Expand Down
5 changes: 3 additions & 2 deletions test/tests/json_compare.rb
Expand Up @@ -5,14 +5,15 @@ class JSONCompareTests < Minitest::Test

def setup
@path = File.expand_path "#{TEST_PATH}/apps/rails3.2"
@json_path = File.join @path, "report.json"
File.delete @json_path if File.exist? @json_path
@json_path = File.join @path, "doesnt_exist", "report.json"
teardown # just to be sure
Brakeman.run :app_path => @path, :output_files => [@json_path]
@report = JSON.parse File.read(@json_path)
end

def teardown
File.delete @json_path if File.exist? @json_path
Dir.delete File.dirname(@json_path) if Dir.exist? File.dirname(@json_path)
end

def update_json
Expand Down

0 comments on commit 3b2a8cc

Please sign in to comment.