Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for empty last_run files for parallel tests #533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?