Skip to content

Commit

Permalink
Append to existing log file if it exists instead of rewriting it
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Hu committed Jun 3, 2016
1 parent 7256473 commit 0965643
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/miss_cleo/tests_to_files_map_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def add_to_log(test_file_and_line, lines_run_before, lines_run_after, templates)
end

def export_logs
File.open(file_name, 'w') { |f| f.write JSON.dump logs }
if File.exists?(file_name)
file = JSON.parse(File.read(file_name))
@logs += file
end
File.open(file_name, 'w') { |f| f.write JSON.dump @logs }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/miss_cleo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MissCleo
VERSION = "0.4.7"
VERSION = "0.4.8"
end
10 changes: 10 additions & 0 deletions spec/tests_to_files_map_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,15 @@
expect(File.exists?(file_name)).to be
FileUtils.rm(file_name)
end

it "appends to an existing log" do
file_name = 'test.json'
File.open(file_name, 'w') { |f| f.write JSON.dump [["hello"]] }
logger = described_class.new(file_name)
logger.export_logs
lines = File.read(file_name)
expect(lines).to eq("[[\"hello\"]]")
FileUtils.rm(file_name)
end
end
end

0 comments on commit 0965643

Please sign in to comment.