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

Add RSpecRails/PendingOnlyExampleGroup cop #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

r7kamura
Copy link
Contributor

@r7kamura r7kamura commented Sep 5, 2024

rspec-rails generates this kind of test file skelton,

require 'rails_helper'

RSpec.describe Post do
  pending "add some examples to (or delete) #{__FILE__}"
end

but it is not a good idea to git-add these files without any modification. So I propose to add a cop to suppress it.

In fact, many of the projects I've participated in have included a lot of meaningless pending test files like this, and RSpec was outputting a large amount of logs about them there.


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).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • Set VersionChanged: "<<next>>" in config/default.yml.

@r7kamura r7kamura requested a review from a team as a code owner September 5, 2024 05:23
@bquorning
Copy link
Contributor

I think most of what you want is covered by rubocop-rspec’s Pending cop. Except, that cop will also flag your last test example:

        RSpec.describe Post do
          pending "TODO"

          it 'does something' do
            expect(foo).to eq(1)
          end
        end

@r7kamura
Copy link
Contributor Author

r7kamura commented Sep 5, 2024

As you also pointed out, that would make legitimate pending and skip an offense. I think nothing wrong with marking existing examples as pending or skip for some reason.

@bquorning
Copy link
Contributor

I think a configuration option to RSpec/Pending would be better than a new cop.

@r7kamura
Copy link
Contributor Author

r7kamura commented Sep 6, 2024

I believe that this kind of code is usually not written by humans and would only be generated by rspec-rails. That's why I proposed this cop to rubocop-rspec_rails. But I also agree that it should be proposed as an option for RSpec/Pending, since looking at the cop logic alone, there is no special Rails involvement 🤔

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.

2 participants