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

Add new `RSpec/MultipleTestTargetsPerSpecFile` cop

Open ydah opened this issue 2 years ago • 1 comments

Resolve: https://github.com/rubocop/rubocop-rspec/issues/1691


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 created a new cop:

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

ydah avatar Aug 16 '23 16:08 ydah

/Users/pirj/source/real-world-rspec/sharetribe/spec/services/util_spec.rb:44:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
describe StringUtils do
^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/services/util_spec.rb:66:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
describe ArrayUtils do
^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/services/result.rb:78:3: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
  describe Result::Success do
  ^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/services/result.rb:173:3: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
  describe Result::Error do
  ^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/controllers/application_controller_spec.rb:154:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
describe ApplicationController, type: :controller do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/controllers/application_controller_spec.rb:238:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
describe ApplicationController, type: :controller do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/sharetribe/spec/controllers/application_controller_spec.rb:256:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
describe ApplicationController, type: :controller do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/rspec-mocks/spec/rspec/mocks/matchers/have_received_spec.rb:665:5: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
    RSpec.describe Matchers::HaveReceived, "when used in a context that has rspec-mocks and rspec-expectations available" do
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/rspec-mocks/spec/rspec/mocks/matchers/have_received_spec.rb:675:5: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
    RSpec.describe Matchers::HaveReceived, "when used in a context that has only rspec-mocks available" do
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/rspec-expectations/spec/rspec/matchers/built_in/change_spec.rb:1036:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
RSpec.describe RSpec::Matchers::BuiltIn::Change do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/rspec-expectations/spec/rspec/matchers/built_in/change_spec.rb:1058:1: C: RSpec/MultipleTestTargetsPerSpecFile: Spec files should only include one test target object.
RSpec.describe RSpec::Matchers::BuiltIn::ChangeRelatively do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

At a glance, there are a few false positives, and it feels that the cop should be more permissive.

pirj avatar Aug 21 '23 07:08 pirj

Now I'm rethinking whether I really need this Cop. As mentioned in the comments below, it may not be extracted to a separate file for smaller internal classes, and since there is no similar cop on the rubocop/rubocop side, it does not make sense that this cop exists only on the RuboCop RSpec side. So I decided to close this PR.

  • https://github.com/rubocop/rubocop-rspec/issues/1691

ydah avatar Feb 29 '24 16:02 ydah