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

Handle multi-command resultsets #163

Merged
merged 4 commits into from
Dec 29, 2016
Merged
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
1 change: 1 addition & 0 deletions Gemfile.ruby-19
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ source "https://rubygems.org"

gem "addressable", "< 2.5"
gem "json", "~> 1.8", "< 2"
gem "webmock", "< 2.3.1"

gemspec
30 changes: 22 additions & 8 deletions lib/code_climate/test_reporter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
module CodeClimate
module TestReporter
class Formatter
class InvalidSimpleCovResultError < StandardError; end

def format(results)
begin
validated_results = results.values.fetch(0).fetch("coverage")
rescue NoMethodError, KeyError => ex
raise InvalidSimpleCovResultError, ex.message
simplecov_results = results.map do |command_name, data|
SimpleCov::Result.from_hash(command_name => data)
end

simplecov_results = SimpleCov::Result.new(validated_results)
simplecov_result =
if simplecov_results.size == 1
simplecov_results.first
else
merge_results(simplecov_results)
end

payload = to_payload(simplecov_results)
payload = to_payload(simplecov_result)
PayloadValidator.validate(payload)

payload
Expand Down Expand Up @@ -85,6 +86,19 @@ def to_payload(result)
def round(numeric, precision)
Float(numeric).round(precision)
end

# Re-implementation of Simplecov::ResultMerger#merged_result, which is
# needed because calling it directly gets you into caching land with files
# on disk.
def merge_results(results)
merged = {}
results.each do |result|
merged = result.original_result.merge_resultset(merged)
end
result = SimpleCov::Result.new(merged)
result.command_name = results.map(&:command_name).sort.join(", ")
result
end
end
end
end
Binary file added spec/fixtures/issue_7.tar.gz
Binary file not shown.
Loading