diff --git a/lib/brakeman.rb b/lib/brakeman.rb index b549c224b3..e002b0f713 100644 --- a/lib/brakeman.rb +++ b/lib/brakeman.rb @@ -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 diff --git a/test/tests/json_compare.rb b/test/tests/json_compare.rb index 452063a8cd..10a1cc1c67 100644 --- a/test/tests/json_compare.rb +++ b/test/tests/json_compare.rb @@ -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