rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

Add named_only style for RSpec/NamedSubject cop

Open kuahyeow opened this issue 5 years ago • 1 comments

This adds named_only style for the RSpec/NamedSubject cop. It is intended as a smaller step to first catch explicit subject references where the subject(:name) { .. } is named.

We keep the default style (I have named it always).


Before submitting the PR make sure the following are checked:

  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [x] Updated documentation.
  • [x] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • [x] 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:

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

kuahyeow avatar Sep 19 '20 08:09 kuahyeow

@pirj Thanks for the nice review ! I have added changes as requested, please see each thread above.

kuahyeow avatar Oct 01 '20 10:10 kuahyeow

Nice addition. Any release planned soon?

Should this cop also ignore implicit subjects? This would be useful when is_expected is not recommanded by RSpec/ImplicitSubject and no explicit subject is defined.

RSpec.describe Klass do
  it do
    prepare_something_to_be_true
    expect(subject).to be_something
  end
end

inkstak avatar Oct 13 '22 14:10 inkstak

Thanks for the bump, @inkstak . Let me quickly rebase it.

pirj avatar Oct 13 '22 14:10 pirj

@bquorning @Darhazer WDYT?

pirj avatar Oct 13 '22 15:10 pirj

@bquorning I won't be merging this so far, not to interfere with the release.

pirj avatar Oct 23 '22 21:10 pirj

Thank you, @kuahyeow ! Please accept our apologies it took two years to merge.

pirj avatar Oct 23 '22 22:10 pirj