Skip to content

Add simplecov to measure test coverage of our code #1534

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

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Dec 27, 2022

This PR is add simplecov to measure test coverage of our code.

Branch coverage is enabled, but minimum coverage by file is enabled.

Below the lowest of the current coverage, RSpec will fail as shown below.
This keeps the test coverage of our code high.

fail


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • [-] Added tests.
  • [-] Updated documentation.
  • [-] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@@ -17,3 +17,6 @@ pkg

.ruby-gemset
.ruby-version

# simplecov generated
coverage
Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] Avoid git management of generated files.

Comment on lines 3 to 9
require 'simplecov'

SimpleCov.start do
enable_coverage :branch
add_filter '/spec/'
end

Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] Currently, rspec always measures coverage when it is run.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thank you!

Gemfile Outdated
@@ -10,6 +10,7 @@ gem 'rake'
gem 'rspec', '~> 3.11'
gem 'rubocop-performance', '~> 1.7'
gem 'rubocop-rake', '~> 0.6'
gem 'simplecov'
Copy link
Member

Choose a reason for hiding this comment

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

While we're at it, have you tried https://github.com/grosser/single_cov ?
I have no experience with it, and have no idea if it provides such a pretty report as Simplecov.

Copy link
Member Author

@ydah ydah Dec 28, 2022

Choose a reason for hiding this comment

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

# spec/spec_helper.rb
SingleCov.setup :rspec

The following was going to need to be added to all specs.

require 'spec_helper'
SingleCov.covered!

If there are areas not covered by the test as shown below, the following output is likely to be present.

lib/rubocop/cop/rspec/align_left_let_brace.rb new uncovered lines introduced (1 current vs 0 configured)
Lines missing coverage:
lib/rubocop/cop/rspec/align_left_let_brace.rb:25

Personally, I think simplecov looks good, what do you think?

@nijikon
Copy link
Collaborator

nijikon commented Dec 27, 2022

@ydah can you add minimal coverage?

@pirj

This comment was marked as resolved.

@nijikon
Copy link
Collaborator

nijikon commented Dec 28, 2022

What I meant is to add SimpleCov.minimum_coverage(<current value>). The rspec command will fail if the coverage is not on at least the current level.

@nijikon

This comment was marked as resolved.

@ydah ydah force-pushed the add-simplecov branch 2 times, most recently from e8a3b50 to a5f3c41 Compare December 28, 2022 11:07

SimpleCov.start do
enable_coverage :branch
minimum_coverage line: 99.86, branch: 95.33
Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] Current coverage is specified.

@@ -3,6 +3,8 @@
require 'rubocop'
require 'rubocop/rspec/support'

require 'simplecov' unless ENV['NO_COVERAGE']
Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] Turned on/off by environment variable, but usually enabled coverage

with:
ruby-version: "${{ matrix.ruby }}"
bundler-cache: true
- run: NO_COVERAGE=true bundle exec rake ${{ matrix.task }}
Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] Since there is no need to measure coverage for each version, it is disabled here.

bundler-cache: true
- run: NO_COVERAGE=true bundle exec rake ${{ matrix.task }}

coverage:
Copy link
Member Author

Choose a reason for hiding this comment

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

[memo] New coverage job is being created only check coverage.

@ydah ydah requested a review from pirj December 28, 2022 12:08
@ydah ydah force-pushed the add-simplecov branch 2 times, most recently from 1dbb3f9 to 4d6e015 Compare December 28, 2022 12:13
@ydah
Copy link
Member Author

ydah commented Dec 28, 2022

@nijikon I added minimal coverage to match the current coverage. What do you think?

@nijikon
Copy link
Collaborator

nijikon commented Dec 28, 2022

@ydah looks good on my end, let's merge and see how this will work

@ydah
Copy link
Member Author

ydah commented Dec 28, 2022

The coverage report seems to be generated on ci, but there's no way to access it. Does it make sense to make it add its output to all RSpec jobs? Or doing one run for one Ruby version would be sufficient? 🤔

@pirj RSpec will fail if the coverage is below the minimum. So I don't seem to need to do anything on the GitHub Actions side, what do you think?

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thank you!

@pirj pirj requested review from bquorning and Darhazer December 29, 2022 08:02
This PR is add [simplecov](https://github.com/simplecov-ruby/simplecov) to measure test coverage of our code

Branch coverage is enabled, but [minimum coverage by file](https://github.com/simplecov-ruby/simplecov#minimum-coverage-by-file) is also enabled.
Copy link
Member

@Darhazer Darhazer left a comment

Choose a reason for hiding this comment

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

Great 👍
I'll leave the final decision to @bquorning

Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

Thank you

@bquorning bquorning merged commit c430668 into rubocop:master Jan 3, 2023
@ydah ydah deleted the add-simplecov branch January 3, 2023 08:18
ydah added a commit to rubocop/rubocop-capybara that referenced this pull request Jan 3, 2023
ydah added a commit to rubocop/rubocop-capybara that referenced this pull request Jan 3, 2023
ydah added a commit to rubocop/rubocop-capybara that referenced this pull request Jan 3, 2023
ydah added a commit to rubocop/rubocop-capybara that referenced this pull request Jan 3, 2023
@bquorning bquorning added this to the Code coverage milestone Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants