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 #1337] Update the cop to raise error for insufficient descriptions. #1350

Conversation

akrox58
Copy link

@akrox58 akrox58 commented Aug 3, 2022

Per issue #1337, I tried to add a generic way to the ExampleWordingCop to call out insufficient descriptions. For now, I've used "works" and "throws errors" as that is a phrase I see used often as well. I didn't use a new cop since insufficient descriptions seemed to be along the same lines as "should not start with should or it" as they are both description related.


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 modified an existing cop's configuration options:

  • Set VersionChanged in config/default.yml to the next major version.

Copy link
Member

@ydah ydah left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you.

@akrox58
Copy link
Author

akrox58 commented Aug 5, 2022

Thanks @ydah! How do I get this merged? Do I need to wait for the other reviewers to approve?

@akrox58 akrox58 requested a review from pirj August 5, 2022 17:52
@akrox58 akrox58 force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from 0cbe7ad to 50d871d Compare August 6, 2022 16:27
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.

I would expect the following to pass, but it fails, why?

    expect_no_offenses(<<-'RUBY')
      it "works" \
        "totally fine" do
      end
    RUBY

@akrox58
Copy link
Author

akrox58 commented Aug 7, 2022

I would expect the following to pass, but it fails, why?

    expect_no_offenses(<<-'RUBY')
      it "works" \
        "totally fine" do
      end
    RUBY

Looks like I didn't handle that edge case! updated the check to check for the entire description instead, and added some more test cases! Thanks for the catch!

@akrox58 akrox58 force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from 38aafe8 to df850fd Compare August 7, 2022 17:33
@akrox58 akrox58 requested review from pirj and bquorning August 7, 2022 17:33
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.

I've checked against https://github.com/pirj/real-world-rspec, no errors, and the cop "just works" 😄

...
/Users/pirj/source/real-world-rspec/sharetribe/spec/models/person_spec.rb:338:9: C: [Correctable] RSpec/ExampleWording: Your test should be more descriptive.
    it 'works' do
        ^^^^^
/Users/pirj/source/real-world-rspec/solidus/core/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb:41:11: C: [Correctable] RSpec/ExampleWording: Your test should be more descriptive.
      it 'works' do
          ^^^^^

57497 files inspected, 273 offenses detected, 273 offenses autocorrectable

Looks great, thank you for the contribution!

Comment on lines +371 to +387
DisallowedExamples:
- works
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking out loud.
RuboCop is known to override the default if an array configured in the user's configuration. E.g.

RSpec/ContextWording:
  Prefixes:
    - who

Would remove the default when/with/without prefixes.

It may change in RuboCop 2.0. Still, we provide the future behaviour by using inherit_mode:/merge now.

The benefit is that users:

  • won't have to copy over the defaults from the default config
  • won't have to follow and replicate changes when we change the default config
  • use third-party configs that extend our defaults

One downside I can think of is inconsistency of this configuration with the rest of array options.

Copy link
Author

Choose a reason for hiding this comment

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

@pirj Is there something I would need to do to address this?

Copy link
Member

Choose a reason for hiding this comment

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

No, it is fine. Just thinking out loud to get an opinion of maintainers.
For me, this change is totally fine as is.

@pirj pirj requested a review from Darhazer August 7, 2022 18:28
@akrox58 akrox58 force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from df850fd to f074400 Compare August 9, 2022 18:02
@bquorning
Copy link
Collaborator

I have renamed some of the required CI checks, which unfortunately means that you will need to rebase this branch to make CI pass.

@pirj pirj force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch 3 times, most recently from ced82d0 to 13fd06c Compare October 10, 2022 16:06
@pirj
Copy link
Member

pirj commented Oct 10, 2022

Rebased and green @bquorning @Darhazer

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.

This cop will also look for insufficient examples and call them out.

Use the DisallowedExamples setting to prevent unclear or insufficient descriptions.

MSG_INSUFFICIENT_DESCRIPTION = 'Your test should be more descriptive.'

I think we use a more clear terminology. Internally in rspec-core, the first argument to it is called desc. So perhaps

This cop will also look for insufficient example descriptions and call them out.

Use the DisallowedExampleDescriptions setting to prevent unclear or insufficient example descriptions.

MSG_INSUFFICIENT_DESCRIPTION = 'Your example description is insufficient.'

CHANGELOG.md Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/example_wording.rb Show resolved Hide resolved
@pirj pirj force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from b7a022c to e90887a Compare October 13, 2022 15:48
@pirj pirj requested a review from bquorning October 13, 2022 15:55
@pirj pirj force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from e90887a to ce30e66 Compare October 13, 2022 20:44
@pirj pirj force-pushed the FIX-1337/update_example_wording_cop_to_call_out_insufficient_descriptions branch from ce30e66 to 31c1dd7 Compare October 13, 2022 20:46
@pirj pirj merged commit d16fb33 into rubocop:master Oct 13, 2022
@pirj
Copy link
Member

pirj commented Oct 13, 2022

Thank you for the contribution and your time, @akrox58 !

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.

None yet

4 participants