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

Fix NoMethodError in merge_coverage Method #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rspec_tracer/coverage_reporter.rb
Expand Up @@ -72,6 +72,7 @@ def merge_coverage(missed_coverage)
end

line_coverage.each_pair do |line_number, strength|
next unless strength && line_coverage_dup[line_number.to_i]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check added to the merge_coverage method effectively prevents the NoMethodError by ensuring both strength is not nil and the line number exists in line_coverage_dup before attempting to add coverage strengths. This is a direct and effective solution to the problem described in the PR objectives.

However, for improved readability, consider extracting the condition into a well-named method or variable. This can make the intent of the condition clearer and the code easier to understand at a glance.

- next unless strength && line_coverage_dup[line_number.to_i]
+ line_number_exists = line_coverage_dup[line_number.to_i]
+ next unless strength && line_number_exists

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
next unless strength && line_coverage_dup[line_number.to_i]
line_number_exists = line_coverage_dup[line_number.to_i]
next unless strength && line_number_exists

line_coverage_dup[line_number.to_i] += strength
end

Expand Down