Skip to content

Commit

Permalink
Allow for empty last_run files for parallel tests that end up running…
Browse files Browse the repository at this point in the history
… no tests
  • Loading branch information
Chad Shaffer committed Nov 4, 2016
1 parent 6e5ec23 commit 19bc92e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Unreleased ([changes](https://github.com/colszowka/simplecov/compare/v0.12.0...m

## Bugfixes

* Fix parallel_tests where one thread ends up running no tests. See [#533](https://github.com/colszowka/simplecov/pull/533) (thanks @cshaffer)

0.12.0 2016-07-02 ([changes](https://github.com/colszowka/simplecov/compare/v0.11.2...v0.12.0))
=================

Expand Down
3 changes: 2 additions & 1 deletion lib/simplecov/last_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def last_run_path

def read
return nil unless File.exist?(last_run_path)
JSON.parse(File.read(last_run_path))
json = File.read(last_run_path)
JSON.parse(json) unless json.strip.empty?
end

def write(json)
Expand Down
45 changes: 45 additions & 0 deletions spec/last_run_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "helper"

describe SimpleCov::LastRun do
subject { SimpleCov::LastRun }

it "defines a last_run_path" do
expect(subject.last_run_path).to eq(File.join(SimpleCov.coverage_path, ".last_run.json"))
end

it "writes json to its last_run_path" do
json = []
subject.write(json)
expect(File.read(subject.last_run_path).strip).to eq(JSON.pretty_generate(json))
end

context "reading" do
context "but the last_run file does not exist" do
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }

it "returns nil" do
expect(subject.read).to be_nil
end
end

context "a non empty result" do
before { subject.write([]) }

it "reads json from its last_run_path" do
expect(subject.read).to eq(JSON.parse("[]"))
end
end

context "an empty result" do
before do
File.open(subject.last_run_path, "w+") do |f|
f.puts ""
end
end

it "returns nil" do
expect(subject.read).to be_nil
end
end
end
end if SimpleCov.usable?

0 comments on commit 19bc92e

Please sign in to comment.