Skip to content

Commit

Permalink
Stop polluting ::Array and ::Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda authored and craiglittle committed Feb 13, 2016
1 parent b6d4c3b commit 9e4721e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lib/simplecov/merge_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ def merge_resultset(hash)
end

new_resultset.each_key do |filename|
new_resultset[filename] = (self[filename] || []).merge_resultset(hash[filename] || [])
new_resultset[filename] = (self[filename] || []).extend(SimpleCov::ArrayMergeHelper).merge_resultset(hash[filename] || [])
end
new_resultset
end
end
end

Array.send :include, SimpleCov::ArrayMergeHelper
Hash.send :include, SimpleCov::HashMergeHelper
1 change: 1 addition & 0 deletions lib/simplecov/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Result
# Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
# coverage data)
def initialize(original_result)
original_result = original_result.dup.extend(SimpleCov::HashMergeHelper) unless original_result.is_a? SimpleCov::HashMergeHelper
@original_result = original_result.freeze
@files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
Expand Down
2 changes: 1 addition & 1 deletion spec/merge_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
source_fixture("resultset1.rb") => [1, 1, 1, 1],
}
}.extend(SimpleCov::HashMergeHelper)

@resultset2 = {
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
Expand Down

0 comments on commit 9e4721e

Please sign in to comment.