From 38a9ed7d95eeb4feddb7f7372d3b0918ea70781e Mon Sep 17 00:00:00 2001 From: ydah Date: Thu, 28 Mar 2024 00:00:37 +0900 Subject: [PATCH] RSpec -> RSpecRails --- .github/workflows/main.yml | 21 +- .rubocop.yml | 14 +- .simplecov | 2 +- CHANGELOG.md | 911 +------------ README.md | 44 +- Rakefile | 31 +- config/default.yml | 1157 +---------------- docs/antora.yml | 4 +- docs/modules/ROOT/nav.adoc | 6 - docs/modules/ROOT/pages/cops.adoc | 148 +-- docs/modules/ROOT/pages/cops_rspecrails.adoc | 32 +- docs/modules/ROOT/pages/development.adoc | 31 +- docs/modules/ROOT/pages/index.adoc | 53 +- docs/modules/ROOT/pages/installation.adoc | 6 +- docs/modules/ROOT/pages/usage.adoc | 74 +- lib/rubocop-rspec_rails.rb | 62 +- .../cop/rspec_rails/avoid_setup_hook.rb | 56 +- .../cop/rspec_rails/have_http_status.rb | 116 +- lib/rubocop/cop/rspec_rails/http_status.rb | 332 +++-- .../cop/rspec_rails/inferred_spec_type.rb | 232 ++-- .../cop/rspec_rails/minitest_assertions.rb | 575 ++++---- .../cop/rspec_rails/negation_be_valid.rb | 152 ++- lib/rubocop/cop/rspec_rails/travel_around.rb | 140 +- lib/rubocop/cop/rspec_rails_cops.rb | 140 +- lib/rubocop/rspec_rails/config_formatter.rb | 27 +- .../rspec_rails/description_extractor.rb | 19 +- lib/rubocop/rspec_rails/version.rb | 6 +- rubocop-rspec_rails.gemspec | 26 +- spec/project/default_config_spec.rb | 52 +- .../cop/rspec_rails/avoid_setup_hook_spec.rb | 2 +- .../cop/rspec_rails/have_http_status_spec.rb | 2 +- .../cop/rspec_rails/http_status_spec.rb | 2 +- .../rspec_rails/inferred_spec_type_spec.rb | 2 +- .../rspec_rails/minitest_assertions_spec.rb | 2 +- .../cop/rspec_rails/negation_be_valid_spec.rb | 2 +- .../cop/rspec_rails/travel_around_spec.rb | 2 +- spec/spec_helper.rb | 10 +- tasks/cops_documentation.rake | 65 +- 38 files changed, 981 insertions(+), 3577 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06093c25..406f52af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,7 +69,26 @@ jobs: - uses: actions/checkout@v4 - name: Use latest RuboCop from `master` run: | - echo "gem 'rubocop', github: 'rubocop/rubocop'" > Gemfile.local + echo "gem 'rubocop', github: 'rubocop-hq/rubocop'" > Gemfile.local + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + bundler-cache: true + - run: NO_COVERAGE=true bundle exec rake ${{ matrix.task }} + + edge-rubocop-rspec: + runs-on: ubuntu-latest + strategy: + matrix: + task: + - internal_investigation + - spec + name: "Edge RuboCop RSpec: ${{ matrix.task }}" + steps: + - uses: actions/checkout@v4 + - name: Use latest RuboCop RSpec from `master` + run: | + echo "gem 'rubocop-rspec', github: 'rubocop/rubocop-rspec'" > Gemfile.local - uses: ruby/setup-ruby@v1 with: ruby-version: "3.3" diff --git a/.rubocop.yml b/.rubocop.yml index df3d9b9b..cc9d7ca4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -49,13 +49,13 @@ Lint/RedundantCopDisableDirective: Metrics/BlockLength: Exclude: - - rubocop-rspec.gemspec + - rubocop-rspec_rails.gemspec - Rakefile - '**/*.rake' Naming/FileName: Exclude: - - lib/rubocop-rspec.rb + - lib/rubocop-rspec_rails.rb Naming/InclusiveLanguage: Enabled: true @@ -85,9 +85,6 @@ Naming/InclusiveLanguage: violation: Suggestions: - offense - 'register no offense': - Suggestions: - - registers no offense RSpec: Language: @@ -118,11 +115,6 @@ Style/FormatStringToken: Style/RequireOrder: Enabled: true -RSpec/SpecFilePathFormat: - Enabled: true - Exclude: - - spec/rubocop/cop/rspec/mixin/**/*.rb - # Enable some of RuboCop's pending cops. Layout/LineContinuationSpacing: @@ -142,7 +134,7 @@ Style/RedundantStringEscape: Style/ReturnNilInPredicateMethodDefinition: Enabled: true -# Enable our own pending cops. +# Enable pending rubocop-rspec cops. RSpec/BeEmpty: Enabled: true diff --git a/.simplecov b/.simplecov index c09a9b47..a1e3bd94 100644 --- a/.simplecov +++ b/.simplecov @@ -2,7 +2,7 @@ SimpleCov.start do enable_coverage :branch - minimum_coverage line: 99.60, branch: 94.77 + minimum_coverage line: 95.17, branch: 85.13 add_filter '/spec/' add_filter '/vendor/bundle/' end diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c008527..7377149e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,67 +2,15 @@ ## Master (Unreleased) -## 2.27.1 (2024-03-03) +- Extracted from `rubocop-rspec` into a separate repository. ([@ydah]) -- Fix a false positive for `RSpec/RepeatedSubjectCall` when `subject.method_call`. ([@ydah]) -- Add configuration option `OnlyStaticConstants` to `RSpec/DescribedClass`. ([@ydah]) +## Previously (see [rubocop-rspec's changelist](https://github.com/rubocop/rubocop-rspec/blob/v2.27.1/CHANGELOG.md) for details) -## 2.27.0 (2024-03-01) - -- Add new `RSpec/IsExpectedSpecify` cop. ([@ydah]) -- Add new `RSpec/RepeatedSubjectCall` cop. ([@drcapulet]) - Add support for `assert_true`, `assert_false`, `assert_not_equal`, `assert_not_nil`, `*_empty`, `*_predicate`, `*_kind_of`, `*_in_delta`, `*_match`, `*_instance_of` and `*_includes` assertions in `RSpec/Rails/MinitestAssertions`. ([@ydah], [@G-Rath]) -- Support asserts with messages in `Rspec/BeEmpty`. ([@G-Rath]) -- Fix a false positive for `RSpec/ExpectActual` when used with rspec-rails routing matchers. ([@naveg]) - Add configuration option `ResponseMethods` to `RSpec/Rails/HaveHttpStatus`. ([@ydah]) -- Fix a false negative for `RSpec/DescribedClass` when class with constant. ([@ydah]) -- Fix a false positive for `RSpec/ExampleWithoutDescription` when `specify` with multi-line block and missing description. ([@ydah]) -- Fix an incorrect autocorrect for `RSpec/ChangeByZero` when compound expectations with line break before `.by(0)`. ([@ydah]) - -## 2.26.1 (2024-01-05) - -- Fix an error for `RSpec/SharedExamples` when using examples without argument. ([@ydah]) - -## 2.26.0 (2024-01-04) - -- Add new `RSpec/RedundantPredicateMatcher` cop. ([@ydah]) -- Add new `RSpec/RemoveConst` cop. ([@swelther]) -- Add support for correcting "it will" (future tense) for `RSpec/ExampleWording`. ([@jdufresne]) -- Add support for `symbol` style for `RSpec/SharedExamples`. ([@jessieay]) -- Ensure `PendingWithoutReason` can detect violations inside shared groups. ([@robinaugh]) - -## 2.25.0 (2023-10-27) - - Add support single quoted string and percent string and heredoc for `RSpec/Rails/HttpStatus`. ([@ydah]) -- Change to be inline disable for `RSpec/SpecFilePathFormat` like `RSpec/FilePath`. ([@ydah]) -- Fix a false positive for `RSpec/MetadataStyle` with example groups having multiple string arguments. ([@franzliedke]) - -## 2.24.1 (2023-09-23) - -- Fix an error when using `RSpec/FilePath` and revert to enabled by default. If you have already moved to `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat`, disable `RSpec/FilePath` explicitly as `Enabled: false`. The `RSpec/FilePath` before migration and the `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat` as the target are available respectively. ([@ydah]) - -## 2.24.0 (2023-09-08) - -- Split `RSpec/FilePath` into `RSpec/SpecFilePathSuffix` and `RSpec/SpecFilePathFormat`. `RSpec/FilePath` cop is disabled by default and the two new cops are pending and need to be enabled explicitly. ([@ydah]) -- Add new `RSpec/Eq` cop. ([@ydah]) -- Add `RSpec/MetadataStyle` and `RSpec/EmptyMetadata` cops. ([@r7kamura]) - Add support `RSpec/Rails/HttpStatus` when `have_http_status` with string argument. ([@ydah]) -- Fix an infinite loop error when `RSpec/ExcessiveDocstringSpacing` finds a description with non-ASCII leading/trailing whitespace. ([@bcgraham]) -- Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when return values declared between stubs. ([@marocchino]) -- Fix a false positive `RSpec/Focus` when chained method call and inside define method. ([@ydah]) - -## 2.23.2 (2023-08-09) - -- Fix an incorrect autocorrect for `RSpec/ReceiveMessages` when method is only non-word character. ([@marocchino]) -- Fix a false positive for `RSpec/ReceiveMessages` when return with splat. ([@marocchino]) - -## 2.23.1 (2023-08-07) - - Mark to `Safe: false` for `RSpec/Rails/NegationBeValid` cop. ([@ydah]) -- Declare autocorrect as unsafe for `RSpec/ReceiveMessages`. ([@bquorning]) - -## 2.23.0 (2023-07-30) - - Add new `RSpec/Rails/NegationBeValid` cop. ([@ydah]) - Fix a false negative for `RSpec/ExcessiveDocstringSpacing` when finds description with em space. ([@ydah]) - Fix a false positive for `RSpec/EmptyExampleGroup` when example group with examples defined in `if` branch inside iterator. ([@ydah]) @@ -74,890 +22,35 @@ - Fix `RSpec/NamedSubject` when block has no body. ([@splattael]) - Fix `RSpec/LetBeforeExamples` autocorrect incompatible with `RSpec/ScatteredLet` autocorrect. ([@ydah]) - Update `RSpec/Focus` to support `shared_context` and `shared_examples`. ([@tmaier]) - -## 2.22.0 (2023-05-06) - -- Extract factory_bot cops to a separate repository, [`rubocop-factory_bot`](https://github.com/rubocop/rubocop-factory_bot). The `rubocop-factory_bot` repository is a dependency of `rubocop-rspec` and the factory_bot cops are aliased (`RSpec/FactoryBot/Foo` == `FactoryBot/Foo`) until v3.0 is released, so the change will be invisible to users until then. ([@ydah]) - -## 2.21.0 (2023-05-05) - -- Fix a false positive in `RSpec/IndexedLet` with suffixes after index-like numbers. ([@pirj]) - Fix an error for `RSpec/Rails/HaveHttpStatus` with comparison with strings containing non-numeric characters. ([@ydah]) -- Fix an error for `RSpec/MatchArray` when `match_array` with no argument. ([@ydah]) -- Add support `a_block_changing` and `changing` for `RSpec/ChangeByZero`. ([@ydah]) -- Drop Ruby 2.6 support. ([@ydah]) - -## 2.20.0 (2023-04-18) - -- Add new `RSpec/IndexedLet` cop. ([@dmitrytsepelev]) -- Add new `RSpec/BeEmpty` cop. ([@ydah], [@bquorning]) -- Add autocorrect support for `RSpec/ScatteredSetup`. ([@ydah]) - Add support `be_status` style for `RSpec/Rails/HttpStatus`. ([@ydah]) -- Add support for shared example groups to `RSpec/EmptyLineAfterExampleGroup`. ([@pirj]) -- Add support for `RSpec/HaveHttpStatus` when using `response.code`. ([@ydah]) - Fix order of expected and actual in correction for `RSpec/Rails/MinitestAssertions`. ([@mvz]) -- Fix a false positive for `RSpec/DescribedClassModuleWrapping` when RSpec.describe numblock is nested within a module. ([@ydah]) -- Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on. ([@dmitrytsepelev]) -- Fix a false positive for `RSpec/PendingWithoutReason` when pending/skip has a reason inside an example group. ([@ydah]) -- Fix a false negative for `RSpec/RedundantAround` when redundant numblock `around`. ([@ydah]) -- Change `RSpec/ContainExactly` to ignore calls with no arguments, and change `RSpec/MatchArray` to ignore calls with an empty array literal argument. ([@ydah], [@bquorning]) -- Make `RSpec/MatchArray` and `RSpec/ContainExactly` pending. ([@ydah]) - -## 2.19.0 (2023-03-06) - -- Fix a false positive for `RSpec/ContextWording` when context is interpolated string literal or execute string. ([@ydah]) -- Fix a false positive for `RSpec/DescribeMethod` when multi-line describe without `#` and `.` at the beginning. ([@ydah], [@pirj]) -- Fix a false positive for `RSpec/VariableName` when inside non-spec code. ([@ydah]) -- Fix a false positive for `RSpec/VariableDefinition` when inside non-spec code. ([@ydah]) -- Add new `RSpec/PendingBlockInsideExample` cop. ([@ydah]) -- Add `RSpec/RedundantAround` cop. ([@r7kamura]) - Add `RSpec/Rails/TravelAround` cop. ([@r7kamura]) -- Add `RSpec/ContainExactly` and `RSpec/MatchArray` cops. ([@faucct]) -- Fix a false positive for `RSpec/PendingWithoutReason` when not inside example and pending/skip with block. ([@ydah], [@pirj]) -- Fix a false positive for `RSpec/PendingWithoutReason` when `skip` is passed a block inside example. ([@ydah], [@pirj]) -- Rename `RSpec/PendingBlockInsideExample` cop to `RSpec/SkipBlockInsideExample`. ([@pirj]) -- Deprecate `send_pattern`/`block_pattern`/`numblock_pattern` helpers in favour of using node pattern explicitly. ([@pirj], [@ydah]) -- Fix an incorrect autocorrect for `RSpec/VerifiedDoubleReference` when namespaced class. ([@ydah]) - -## 2.18.1 (2023-01-19) - -- Add `rubocop-capybara` version constraint to prevent sudden cop enabling when it hits 3.0. ([@pirj]) - -## 2.18.0 (2023-01-16) - -- Extract Capybara cops to a separate repository, [`rubocop-capybara`](https://github.com/rubocop/rubocop-capybara). The `rubocop-capybara` repository is a dependency of `rubocop-rspec` and the Capybara cops are aliased (`RSpec/Capybara/Foo` == `Capybara/Foo`) until v3.0 is released, so the change will be invisible to users until then. ([@pirj]) - -## 2.17.1 (2023-01-16) - -- Fix a false negative for `RSpec/Pending` when using skipped in metadata is multiline string. ([@ydah]) -- Fix a false positive for `RSpec/NoExpectationExample` when using skipped in metadata is multiline string. ([@ydah]) -- Fix a false positive for `RSpec/ContextMethod` when multi-line context with `#` at the beginning. ([@ydah]) -- Fix an incorrect autocorrect for `RSpec/PredicateMatcher` when multiline expect and predicate method with heredoc. ([@ydah]) -- Fix a false positive for `RSpec/PredicateMatcher` when `include` with multiple argument. ([@ydah]) - -## 2.17.0 (2023-01-13) - -- Fix a false positive for `RSpec/PendingWithoutReason` when pending/skip is argument of methods. ([@ydah]) -- Add new `RSpec/Capybara/MatchStyle` cop. ([@ydah]) - Add new `RSpec/Rails/MinitestAssertions` cop. ([@ydah]) -- Fix a false positive for `RSpec/PendingWithoutReason` when not inside example. ([@ydah]) -- Fix a false negative for `RSpec/PredicateMatcher` when using `include` and `respond_to`. ([@ydah]) -- Fix a false positive for `RSpec/StubbedMock` when stubbed message expectation with a block and block parameter. ([@ydah]) - -## 2.16.0 (2022-12-13) - -- Add new `RSpec/FactoryBot/FactoryNameStyle` cop. ([@ydah]) - Improved processing speed for `RSpec/Be`, `RSpec/ExpectActual`, `RSpec/ImplicitExpect`, `RSpec/MessageSpies`, `RSpec/PredicateMatcher` and `RSpec/Rails/HaveHttpStatus`. ([@ydah]) -- Fix wrong autocorrection in `n_times` style on `RSpec/FactoryBot/CreateList`. ([@r7kamura]) -- Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` when using `generate` with multiple arguments. ([@ydah]) -- Mark `RSpec/BeEq` as `Safe: false`. ([@r7kamura]) -- Add `RSpec/DuplicatedMetadata` cop. ([@r7kamura]) -- Mark `RSpec/BeEql` as `Safe: false`. ([@r7kamura]) -- Add `RSpec/PendingWithoutReason` cop. ([@r7kamura]) - -## 2.15.0 (2022-11-03) - -- Fix a false positive for `RSpec/RepeatedDescription` when different its block expectations are used. ([@ydah]) -- Add `named_only` style to `RSpec/NamedSubject`. ([@kuahyeow]) -- Fix `RSpec/FactoryBot/ConsistentParenthesesStyle` to ignore calls without the first positional argument. ([@pirj]) -- Fix `RSpec/FactoryBot/ConsistentParenthesesStyle` to ignore calls inside a Hash or an Array. ([@pirj]) -- Fix `RSpec/NestedGroups` to correctly use `AllowedGroups` config. ([@samrjenkins]) -- Remove `Runners` and `HookScopes` RSpec DSL elements from configuration. ([@pirj]) -- Add `with default RSpec/Language config` helper to `lib` (under `rubocop/rspec/shared_contexts/default_rspec_language_config_context`), to allow use for downstream cops based on `RuboCop::Cop::RSpec::Base`. ([@smcgivern]) - -## 2.14.2 (2022-10-25) - -- Fix an incorrect autocorrect for `FactoryBot/ConsistentParenthesesStyle` with `omit_parentheses` option when method name and first argument are not on same line. ([@ydah]) -- Fix autocorrection loop in `RSpec/ExampleWording` for insufficient example wording. ([@pirj]) -- Fix `RSpec/SortMetadata` not to reorder arguments of `include_`/`it_behaves_like`. ([@pirj]) -- Fix a false positive for `RSpec/NoExpectationExample` when allowed pattern methods with arguments. ([@ydah]) -- Change `RSpec/FilePath` so that it only checks suffix when path is under spec/routing or type is defined as routing. ([@r7kamura]) - -## 2.14.1 (2022-10-24) - - Fix an error for `RSpec/Rails/InferredSpecType` with redundant type before other Hash metadata. ([@ydah]) - -## 2.14.0 (2022-10-23) - -- Add `require_implicit` style to `RSpec/ImplicitSubject`. ([@r7kamura]) -- Fix a false positive for `RSpec/Capybara/SpecificMatcher` when `have_css("a")` without attribute. ([@ydah]) -- Update `RSpec/ExampleWording` cop to raise error for insufficient descriptions. ([@akrox58]) -- Add new `RSpec/Capybara/NegationMatcher` cop. ([@ydah]) -- Add `AllowedPatterns` configuration option to `RSpec/NoExpectationExample`. ([@ydah]) -- Improve `RSpec/NoExpectationExample` cop to ignore examples skipped or pending via metadata. ([@pirj]) -- Add `RSpec/FactoryBot/ConsistentParenthesesStyle` cop. ([@Liberatys]) - Add `RSpec/Rails/InferredSpecType` cop. ([@r7kamura]) -- Add new `RSpec/Capybara/SpecificActions` cop. ([@ydah]) -- Update `config/default.yml` removing deprecated option to make the config correctable by users. ([@ignaciovillaverde]) -- Do not attempt to auto-correct example groups with `include_examples` in `RSpec/LetBeforeExamples`. ([@pirj]) -- Add new `RSpec/SortMetadata` cop. ([@leoarnold]) -- Add support for subject! method to `RSpec/SubjectDeclaration`. ([@ydah]) - -## 2.13.2 (2022-09-23) - -- Fix an error for `RSpec/Capybara/SpecificFinders` with no parentheses. ([@ydah]) -- Fix a false positive for `RSpec/NoExpectationExample` with pending using `skip` or `pending` inside an example. ([@ydah]) -- Exclude `have_text` and `have_content` that raise `ArgumentError` with `RSpec/Capybara/VisibilityMatcher` where `:visible` is an invalid option. ([@ydah]) -- Fix a false negative for `RSpec/Capybara/VisibilityMatcher` with negative matchers. ([@ydah]) - -## 2.13.1 (2022-09-12) - -- Include config/obsoletion.yml in the gemspec. ([@hosamaly]) - -## 2.13.0 (2022-09-12) - -- Fix `RSpec/FilePath` cop missing mismatched expanded namespace. ([@sl4vr]) -- Add new `AllowConsecutiveOneLiners` (default true) option for `Rspec/EmptyLineAfterHook` cop. ([@ngouy]) -- Add autocorrect support for `RSpec/EmptyExampleGroup`. ([@r7kamura]) -- Fix `RSpec/ChangeByZero` with compound expressions using `&` or `|` operators. ([@BrianHawley]) -- Add `RSpec/NoExpectationExample`. ([@r7kamura]) -- Add some expectation methods to default configuration. ([@r7kamura]) -- Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah]) -- Fix a false negative for `RSpec/Capybara/SpecificMatcher` for `have_field`. ([@ydah]) -- Fix a false positive for `RSpec/Capybara/SpecificMatcher` when may not have a `href` by `have_link`. ([@ydah]) -- Add `NegatedMatcher` configuration option to `RSpec/ChangeByZero`. ([@ydah]) -- Add new `RSpec/Capybara/SpecificFinders` cop. ([@ydah]) -- Add support for numblocks to `RSpec/AroundBlock`, `RSpec/EmptyLineAfterHook`, `RSpec/ExpectInHook`, `RSpec/HookArgument`, `RSpec/HooksBeforeExamples`, `RSpec/IteratedExpectation`, and `RSpec/NoExpectationExample`. ([@ydah]) -- Fix incorrect documentation URLs when using `rubocop --show-docs-url`. ([@r7kamura]) -- Add `AllowedGroups` configuration option to `RSpec/NestedGroups`. ([@ydah]) -- Deprecate `IgnoredPatterns` option in favor of the `AllowedPatterns` options. ([@ydah]) -- Add `AllowedPatterns` configuration option to `RSpec/ContextWording`. ([@ydah]) -- Add `RSpec/ClassCheck` cop. ([@r7kamura]) -- Fix a false positive for `RSpec/Capybara/SpecificMatcher` when pseudo-classes. ([@ydah]) -- Fix a false negative for `RSpec/SubjectStub` when the subject is declared with the `subject!` method and called by name. ([@eikes]) -- Support `Array.new(n)` on `RSpec/FactoryBot/CreateList` cop. ([@r7kamura]) - -## 2.12.1 (2022-07-03) - -- Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah]) - -## 2.12.0 (2022-07-02) - -- Fix incorrect path suggested by `RSpec/FilePath` cop when second argument contains spaces. ([@tejasbubane]) -- Fix autocorrect for EmptyLineSeparation. ([@johnny-miyake]) -- Add new `RSpec/Capybara/SpecificMatcher` cop. ([@ydah]) -- Fixed false offense detection in `FactoryBot/CreateList` when a n.times block is including method calls in the factory create arguments. ([@ngouy]) -- Fix error in `RSpec/RSpec/FactoryBot/CreateList` cop for empty block. ([@tejasbubane]) -- Update `RSpec/MultipleExpectations` cop documentation with examples of aggregate_failures use. ([@edgibbs]) -- Declare autocorrect as unsafe for `RSpec/VerifiedDoubleReference`. ([@Drowze]) - Add new `RSpec/Rails/HaveHttpStatus` cop. ([@akiomik]) - -## 2.11.1 (2022-05-18) - -- Fix a regression in `RSpec/ExpectChange` flagging chained method calls. ([@pirj]) - -## 2.11.0 (2022-05-18) - -- Drop Ruby 2.5 support. ([@ydah]) -- Add new `RSpec/ChangeByZero` cop. ([@ydah]) -- Improve `RSpec/ExpectChange` to detect namespaced and top-level constants. ([@M-Yamashita01]) -- Introduce an amendment to `Metrics/BlockLength` to exclude spec files. ([@luke-hill]) - -## 2.10.0 (2022-04-19) - -- Fix a false positive for `RSpec/EmptyExampleGroup` when expectations in case statement. ([@ydah]) -- Add `RSpec/VerifiedDoubleReference` cop. ([@t3h2mas]) -- Make `RSpec/BeNil` cop configurable with a `be_nil` style and a `be` style. ([@bquorning]) -- Fix `Capybara/CurrentPathExpectation` autocorrect incompatible with `Style/TrailingCommaInArguments` autocorrect. ([@ydah]) - -## 2.9.0 (2022-02-28) - -- Add new `RSpec/BeNil` cop. ([@bquorning]) -- Add new `RSpec/BeEq` cop. ([@bquorning]) - -## 2.8.0 (2022-01-24) - -- Fix `RSpec/FactoryBot/SyntaxMethods` and `RSpec/Capybara/FeatureMethods` to inspect shared groups. ([@pirj]) -- Fix `RSpec/LeadingSubject` failure in non-spec code. ([@pirj]) -- Add bad example to `RSpec/SubjectStub` cop. ([@oshiro3]) -- Replace non-styleguide cops `StyleGuide` attribute with `Reference`. ([@pirj]) -- Fix `RSpec/SubjectStub` to disallow stubbing of subjects defined in parent example groups. ([@pirj]) - -## 2.7.0 (2021-12-26) - -- Add new `RSpec/FactoryBot/SyntaxMethods` cop. ([@leoarnold]) -- Exclude `task` type specs from `RSpec/DescribeClass` cop. ([@harry-graham]) - -## 2.6.0 (2021-11-08) - -- Fix merging RSpec DSL configuration from third-party gems. ([@pirj]) -- Fix `RSpec/ExcessiveDocstringSpacing` false positive for multi-line indented strings. ([@G-Rath]) -- Fix `Include` configuration for sub-departments. ([@pirj]) -- Ignore heredocs in `RSpec/ExcessiveDocstringSpacing`. ([@G-Rath]) -- Stop `RSpec/ExampleWording` from trying to correct heredocs. ([@G-Rath]) -- Add autocorrect support for `RSpec/VariableDefinition`. ([@r7kamura]) - -## 2.5.0 (2021-09-21) - -- Declare autocorrect as unsafe for `ExpectChange`. ([@francois-ferrandis]) -- Fix each example for `RSpec/HookArgument`. ([@lokhi]) - Exclude unrelated Rails directories from `RSpec/DescribeClass`. ([@MothOnMars]) -- Add `RSpec/ExcessiveDocstringSpacing` cop. ([@G-Rath]) -- Add `RSpec/SubjectDeclaration` cop. ([@dswij]) -- Fix excessive whitespace removal in `RSpec/EmptyHook` autocorrection. ([@pirj]) -- Bump RuboCop requirement to v1.19.0. ([@pirj]) -- Fix false positive in `RSpec/IteratedExpectation` when there is single, non-expectation statement in the block body. ([@Darhazer]) - -## 2.4.0 (2021-06-09) - -- Update `RSpec/FilePath` to check suffix when given a non-constant top-level node (e.g. features). ([@topalovic]) -- Add missing documentation for `single_statement_only` style of `RSpec/ImplicitSubject` cop. ([@tejasbubane]) -- Fix an exception in `DescribedClass` when accessing a constant on a variable in a spec that is nested in a namespace. ([@rrosenblum]) -- Add new `RSpec/IdenticalEqualityAssertion` cop. ([@tejasbubane]) - Add `RSpec/Rails/AvoidSetupHook` cop. ([@paydaylight]) -- Fix false negative in `RSpec/ExpectChange` cop with block style and chained method call. ([@tejasbubane]) - -## 2.3.0 (2021-04-28) - -- Allow `RSpec/ContextWording` to accept multi-word prefixes. ([@hosamaly]) -- Drop support for ruby 2.4. ([@bquorning]) -- Add `CountAsOne` configuration option to `RSpec/ExampleLength`. ([@stephannv]) -- Fix a false positive for `RSpec/RepeatedExampleGroupBody` when `pending` or `skip` have argument(s). ([@Tietew]) - -## 2.2.0 (2021-02-02) - -- Fix `HooksBeforeExamples`, `LeadingSubject`, `LetBeforeExamples` and `ScatteredLet` autocorrection to take into account inline comments and comments immediately before the moved node. ([@Darhazer]) -- Improve rubocop-rspec performance. ([@Darhazer], [@bquorning]) -- Include `Enabled: true` to prevent a mismatched configuration parameter warning when `RSpec` cops are explicitly enabled in the user configuration. ([@pirj]) - -## 2.1.0 (2020-12-17) - -- Fix `RSpec/FilePath` false positive for relative file path runs with long namespaces. ([@ahukkanen]) -- Update `RSpec/Focus` to have auto-correction. ([@dvandersluis]) - -## 2.0.1 (2020-12-02) - -- Fixed infinite loop in `RSpec/ExpectActual` autocorrection when both expected and actual values are literals. ([@Darhazer]) - -## 2.0.0 (2020-11-06) - -- Remove deprecated class `::RuboCop::Cop::RSpec::Cop`. ([@bquorning]) -- Retire `RSpec/InvalidPredicateMatcher` cop. ([@pirj]) -- Remove the code responsible for filtering files to inspect. ([@pirj]) -- Make RSpec language elements configurable. ([@sl4vr]) -- Remove `CustomIncludeMethods` `RSpec/EmptyExampleGroup` option in favour of the new RSpec DSL configuration. ([@pirj]) -- Enabled pending cop (`RSpec/StubbedMock`). ([@pirj]) - -## 2.0.0.pre (2020-10-22) - -- Update RuboCop dependency to v1.0.0. ([@bquorning]) - Change namespace of several cops (`Capybara/*` -> `RSpec/Capybara/*`, `FactoryBot/*` -> `RSpec/FactoryBot/*`, `Rails/*` -> `RSpec/Rails/*`). ([@pirj], [@bquorning]) - -## 1.44.1 (2020-10-20) - -- Relax `rubocop-ast` version constraint. ([@PhilCoggins]) - -## 1.44.0 (2020-10-20) - -- Move our documentation from rubocop-rspec.readthedocs.io to docs.rubocop.org/rubocop-rspec. ([@bquorning]) -- Add `RSpec/RepeatedIncludeExample` cop. ([@biinari]) -- Add `RSpec/StubbedMock` cop. ([@bquorning], [@pirj]) -- Add `IgnoredMetadata` configuration option to `RSpec/DescribeClass`. ([@Rafix02]) -- Fix false positives in `RSpec/EmptyExampleGroup`. ([@pirj]) -- Fix a false positive for `RSpec/EmptyExampleGroup` when example is defined in an `if` branch. ([@koic]) - -## 1.43.2 (2020-08-25) - -- Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj]) -- Fix subject nesting detection in `RSpec/LeadingSubject`. ([@pirj]) - -## 1.43.1 (2020-08-17) - -- Fix `RSpec/FilePath` when checking a file defining e.g. an empty class. ([@bquorning]) - -## 1.43.0 (2020-08-17) - -- Add a new base cop class `::RuboCop::Cop::RSpec::Base`. The old base class `::RuboCop::Cop::RSpec::Cop` is deprecated, and will be removed in the next major release. ([@bquorning]) -- Add support for subject detection after includes and example groups in `RSpec/LeadingSubject`. ([@pirj]) -- Ignore trailing punctuation in context description prefix. ([@elliterate]) -- Relax `RSpec/VariableDefinition` cop so interpolated and multiline strings are accepted even when configured to enforce the `symbol` style. ([@bquorning]) -- Fix `RSpec/EmptyExampleGroup` to flag example groups with examples in invalid scopes. ([@mlarraz]) -- Fix `RSpec/EmptyExampleGroup` to ignore examples groups with examples defined inside iterators. ([@pirj]) -- Improve `RSpec/NestedGroups`, `RSpec/FilePath`, `RSpec/DescribeMethod`, `RSpec/MultipleDescribes`, `RSpec/DescribeClass`'s top-level example group detection. ([@pirj]) -- Add detection of `let!` with a block-pass or a string literal to `RSpec/LetSetup`. ([@pirj]) -- Add `IgnoredPatterns` configuration option to `RSpec/VariableName`. ([@jtannas]) -- Add `RSpec/MultipleMemoizedHelpers` cop. ([@mockdeep]) - -## 1.42.0 (2020-07-09) - -- Update RuboCop dependency to 0.87.0 because of changes to internal APIs. ([@bquorning], [@Darhazer]) - -## 1.41.0 (2020-07-03) - -- Extend the list of Rails spec types for `RSpec/DescribeClass`. ([@pirj]) -- Fix `FactoryBot/AttributeDefinedStatically` to allow `#traits_for_enum` without a block. ([@harrylewis]) -- Improve the performance of `FactoryBot/AttributeDefinedStatically`, `RSpec/InstanceVariable`, `RSpec/LetSetup`, `RSpec/NestedGroups` and `RSpec/ReturnFromStub`. ([@andrykonchin]) - -## 1.40.0 (2020-06-11) - -- Add new `RSpec/VariableName` cop. ([@tejasbubane]) -- Add new `RSpec/VariableDefinition` cop. ([@tejasbubane]) -- Expand `Capybara/VisibilityMatcher` to support more than just `have_selector`. ([@twalpole]) -- Add new `SpecSuffixOnly` option to `RSpec/FilePath` cop. ([@zdennis]) -- Allow `RSpec/RepeatedExampleGroupBody` to differ only by described_class. ([@robotdana]) -- Fix `RSpec/FilePath` detection across sibling directories. ([@rolfschmidt]) -- Improve the performance of `RSpec/SubjectStub` by an order of magnitude. ([@andrykonchin]) - -## 1.39.0 (2020-05-01) - -- Fix `RSpec/FilePath` detection when absolute path includes test subject. ([@eitoball]) -- Add new `Capybara/VisibilityMatcher` cop. ([@aried3r]) -- Ignore String constants by `RSpec/Describe`. ([@AlexWayfer]) -- Drop support for ruby 2.3. ([@bquorning]) -- Fix multiple cops to detect `let` with proc argument. ([@tejasbubane]) -- Add autocorrect support for `RSpec/ScatteredLet`. ([@Darhazer]) -- Add new `RSpec/EmptyHook` cop. ([@tejasbubane]) - -## 1.38.1 (2020-02-15) - -- Fix `RSpec/RepeatedDescription` to detect descriptions with interpolation and methods. ([@lazycoder9]) - -## 1.38.0 (2020-02-11) - -- Fix `RSpec/InstanceVariable` detection inside custom matchers. ([@pirj]) -- Fix `RSpec/ScatteredSetup` to distinguish hooks with different metadata. ([@pirj]) -- Add autocorrect support for `RSpec/ExpectActual` cop. ([@dduugg], [@pirj]) -- Add `RSpec/RepeatedExampleGroupBody` cop. ([@lazycoder9]) -- Add `RSpec/RepeatedExampleGroupDescription` cop. ([@lazycoder9]) -- Add block name and other lines to `RSpec/ScatteredSetup` message. ([@elebow]) -- Fix `RSpec/RepeatedDescription` to take into account example metadata. ([@lazycoder9]) - -## 1.37.1 (2019-12-16) - -- Improve message and description of `FactoryBot/FactoryClassName`. ([@ybiquitous]) -- Fix `FactoryBot/FactoryClassName` to ignore `Hash` and `OpenStruct`. ([@jfragoulis]) - -## 1.37.0 (2019-11-25) - -- Implement `RSpec/DescribedClassModuleWrapping` to disallow RSpec statements within a module. ([@kellysutton]) -- Fix documentation rake task to support RuboCop 0.75. ([@nickcampbell18]) -- Fix `RSpec/SubjectStub` to detect implicit subjects stubbed. ([@QQism]) -- Fix `RSpec/Pending` not flagging `skip` with string values. ([@pirj]) -- Add `AllowedExplicitMatchers` config option for `RSpec/PredicateMatcher`. ([@mkrawc]) -- Add `FactoryBot/FactoryClassName` cop. ([@jfragoulis]) - -## 1.36.0 (2019-09-27) - -- Fix `RSpec/DescribedClass`'s error when `described_class` is used as part of a constant. ([@pirj]) -- Fix `RSpec/ExampleWording` autocorrect of multi-line docstrings. ([@pirj]) -- Add `RSpec/ContextMethod` cop, to detect method names in `context`. ([@geniou]) -- Update RuboCop dependency to 0.68.1 with support for children matching node pattern syntax. ([@pirj]) -- Add `RSpec/EmptyLineAfterExample` cop to check that there is an empty line after example blocks. ([@pirj]) -- Fix `Capybara/CurrentPathExpectation` auto-corrector, to include option `ignore_query: true`. ([@onumis]) -- Fix `RSpec/Focus` detecting mixed array/hash metadata. ([@dgollahon]) -- Fix `RSpec/Focus` to also detect `pending` examples. ([@dgollahon]) - -## 1.35.0 (2019-08-02) - -- Add `RSpec/ImplicitBlockExpectation` cop. ([@pirj]) - -## 1.34.1 (2019-07-31) - -- Fix `RSpec/DescribedClass`'s error when a local variable is part of the namespace. ([@pirj]) - -## 1.34.0 (2019-07-23) - -- Remove `AggregateFailuresByDefault` config option of `RSpec/MultipleExpectations`. ([@pirj]) -- Add `RSpec/LeakyConstantDeclaration` cop. ([@jonatas], [@pirj]) -- Improve `aggregate_failures` metadata detection of `RSpec/MultipleExpectations`. ([@pirj]) -- Improve `RSpec/SubjectStub` detection and message. ([@pirj]) -- Change message of `RSpec/LetSetup` cop to be more descriptive. ([@foton]) -- Improve `RSpec/ExampleWording` to handle interpolated example messages. ([@nc-holodakg]) -- Improve detection by allowing the use of `RSpec` as a top-level constant. ([@pirj]) -- Fix `RSpec/DescribedClass`'s incorrect detection. ([@pirj]) -- Improve `RSpec/DescribedClass`'s ability to detect inside modules and classes. ([@pirj]) - -## 1.33.0 (2019-05-13) - -- Let `RSpec/DescribedClass` pass `Struct` instantiation closures. ([@schmijos]) -- Fixed `RSpec/ContextWording` missing `context`s with metadata. ([@pirj]) -- Fix `FactoryBot/AttributeDefinedStatically` not working with an explicit receiver. ([@composerinteralia]) -- Add `RSpec/Dialect` enforces custom RSpec dialects. ([@gsamokovarov]) -- Fix redundant blank lines in `RSpec/MultipleSubjects`'s autocorrect. ([@pirj]) -- Drop support for ruby `2.2`. ([@bquorning]) - -## 1.32.0 (2019-01-27) - -- Add `RSpec/Yield` cop, suggesting using the `and_yield` method when stubbing a method, accepting a block. ([@Darhazer]) -- Fix `FactoryBot/CreateList` autocorrect crashing when the factory is called with a block=. ([@Darhazer]) -- Fixed `RSpec/Focus` not flagging some cases of `RSpec.describe` with `focus: true`. ([@Darhazer]) -- Fixed `RSpec/Pending` not flagging some cases of `RSpec.describe` with `:skip`. ([@Darhazer]) -- Fix false positive in `RSpec/ReceiveCounts` when method name `exactly`, `at_least` or `at_most` is used along with `times`, without being an RSpec API. ([@Darhazer]) - -## 1.31.0 (2019-01-02) - -- Add `IgnoreSharedExamples` option for `RSpec/NamedSubject`. ([@RST-J]) -- Add autocorrect support for `Capybara/CurrentPathExpectation` cop. ([@ypresto]) -- Add support for built-in `exists` matcher for `RSpec/PredicateMatcher` cop. ([@mkenyon]) -- `SingleArgumentMessageChain` no longer reports an array as it's only argument as an offense. ([@Darhazer]) - -## 1.30.1 (2018-11-01) - -- `FactoryBot/CreateList` now ignores `times` blocks with an argument. ([@Darhazer]) - -## 1.30.0 (2018-10-08) - -- Add config to `RSpec/VerifiedDoubles` to enforcement of verification on unnamed doubles. ([@BrentWheeldon]) -- Fix `FactoryBot/AttributeDefinedStatically` not working when there is a non-symbol key. ([@vzvu3k6k]) -- Fix false positive in `RSpec/ImplicitSubject` when `is_expected` is used inside `its()` block. ([@Darhazer]) -- Add `single_statement_only` style to `RSpec/ImplicitSubject` as a more relaxed alternative to `single_line_only`. ([@Darhazer]) -- Add `RSpec/UnspecifiedException` as a default cop to encourage more-specific `expect{}.to raise_error(ExceptionType)`, or `raise_exception` style handling of exceptions. ([@daveworth]) - -## 1.29.1 (2018-09-01) - -- Fix false negative in `FactoryBot/AttributeDefinedStatically` when attribute is defined on `self`. ([@Darhazer]) -- `RSpec/FactoryBot` cops will now also inspect the `spec/factories.rb` path by default. ([@bquorning]) - -## 1.29.0 (2018-08-25) - -- `RSpec/InstanceVariable` - Recommend local variables in addition to `let`. ([@jaredbeck]) -- Add `RSpec/ImplicitSubject` cop. ([@Darhazer]) -- Add `RSpec/HooksBeforeExamples` cop. ([@Darhazer]) - -## 1.28.0 (2018-08-14) - -- Add `RSpec/ReceiveNever` cop enforcing usage of `not_to receive` instead of `never` matcher. ([@Darhazer]) -- Fix false positive in `RSpec/EmptyLineAfterExampleGroup` cop when example is inside `if`. ([@Darhazer]) -- Add `RSpec/MissingExampleGroupArgument` to enforce first argument for an example group. ([@geniou]) -- Drop support for ruby `2.1`. ([@bquorning]) -- Add `FactoryBot/AttributeDefinedStatically` cop to help FactoryBot users with the deprecation of static attributes. ([@composerinteralia], [@seanpdoyle]) -- Remove `FactoryBot/DynamicAttributeDefinedStatically` and `FactoryBot/StaticAttributeDefinedDynamically` cops. ([@composerinteralia]) - -## 1.27.0 (2018-06-14) - -- `RSpec/LeadingSubject` now enforces subject to be before any examples, hooks or let declarations. ([@Darhazer]) -- Fix `RSpec/NotToNot` to highlight only the selector (`not_to` or `to_not`), so it works also on `expect { ... }` blocks. ([@bquorning]) -- Add `RSpec/EmptyLineAfterHook` cop. ([@bquorning]) -- Add `RSpec/EmptyLineAfterExampleGroup` cop to check that there is an empty line after example group blocks. ([@bquorning]) -- Fix `RSpec/DescribeClass` crashing on `RSpec.describe` without arguments. ([@Darhazer]) -- Bump RuboCop requirement to v0.56.0. ([@bquorning]) -- Fix `RSpec/OverwritingSetup` crashing if a variable is used as an argument for `let`. ([@Darhazer]) - -## 1.26.0 (2018-06-06) - -- Fix false positive in `RSpec/EmptyExampleGroup` cop when methods named like a RSpec method are used. ([@Darhazer]) -- Fix `Capybara/FeatureMethods` not working when there is require before the spec. ([@Darhazer]) -- Fix `RSpec/EmptyLineAfterFinalLet`: allow a comment to be placed after latest let, requiring empty line after the comment. ([@Darhazer]) -- Add `RSpec/ReceiveCounts` cop to enforce usage of :once and :twice matchers. ([@Darhazer]) - -## 1.25.1 (2018-04-10) - -- Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer]) -- Fix `FactoryBot/DynamicAttributeDefinedStatically` false positive when using symbol proc argument for a sequence. ([@tdeo]) - -## 1.25.0 (2018-04-07) - -- Add `RSpec/SharedExamples` cop to enforce consistent usage of string to titleize shared examples. ([@anthony-robin]) -- Add `RSpec/Be` cop to enforce passing argument to the generic `be` matcher. ([@Darhazer]) -- Fix false positives in `StaticAttributeDefinedDynamically` and `ReturnFromStub` when a const is used in an array or hash. ([@Darhazer]) -- Add `RSpec/Pending` cop to enforce no existing pending or skipped examples. This is disabled by default. ([@patrickomatic]) -- Fix `RSpec/NestedGroups` cop support --auto-gen-config. ([@walf443]) -- Fix false positives in `Capybara/FeatureMethods` when feature methods are used as property names in a factory. ([@Darhazer]) -- Allow configuring enabled methods in `Capybara/FeatureMethods`. ([@Darhazer]) -- Add `FactoryBot/CreateList` cop. ([@Darhazer]) - -## 1.24.0 (2018-03-06) - -- Compatibility with RuboCop v0.53.0. ([@bquorning]) - The `Rails/HttpStatus` cop is unavailable if the `rack` gem cannot be loaded. ([@bquorning]) - Fix `Rails/HttpStatus` not working with custom HTTP status codes. ([@bquorning]) -- Fix `FactoryBot/StaticAttributeDefinedDynamically` to handle empty block. ([@abrom]) -- Fix false positive in `FactoryBot/DynamicAttributeDefinedStatically` when a before/after callback has a symbol proc argument. ([@abrom]) - -## 1.23.0 (2018-02-23) - - Add `RSpec/Rails/HttpStatus` cop to enforce consistent usage of the status format (numeric or symbolic). ([@anthony-robin], [@jojos003]) -- Fix false negative in `RSpec/ReturnFromStub` when a constant is being returned by the stub. ([@Darhazer]) -- Fix `FactoryBot/DynamicAttributeDefinedStatically` to handle dynamic attributes inside arrays/hashes. ([@abrom]) -- Add `FactoryBot/StaticAttributeDefinedDynamically` (based on dynamic attribute cop). ([@abrom]) - -## 1.22.2 (2018-02-01) - -- Fix error in `RSpec/DescribedClass` when working on an empty `describe` block. ([@bquorning]) - -## 1.22.1 (2018-01-17) - -- Fix false positives in `RSpec/ReturnFromStub`. ([@Darhazer]) - -## 1.22.0 (2018-01-10) - -- Updates `describe_class` to account for RSpecs `:system` wrapper of rails system tests. ([@EliseFitz15]) -- Add `RSpec/ExpectChange` cop to enforce consistent usage of the change matcher. ([@Darhazer]) -- Add autocorrect support to `RSpec/LetBeforeExamples`. ([@Darhazer]) -- Fix `RSpec/InstanceVariable` flagging instance variables inside dynamically defined class. ([@Darhazer]) -- Add autocorrect support for `RSpec/ReturnFromStub` cop. ([@bquorning]) -- Add `RSpec/ExampleWithoutDescription` cop. ([@Darhazer]) - -## 1.21.0 (2017-12-13) - -- Compatibility with RuboCop v0.52.0. ([@bquorning]) -- Improve performance when user does not override default RSpec Pattern config. ([@walf443]) -- Add `AggregateFailuresByDefault` configuration for `RSpec/MultipleExpectations` cop. ([@onk]) - -## 1.20.1 (2017-11-15) - -- Add "without" to list of default allowed prefixes for `RSpec/ContextWording`. ([@bquorning]) - -## 1.20.0 (2017-11-09) - -- Rename namespace `FactoryGirl` to `FactoryBot` following original library update. ([@walf443]) -- Fix exception in `RSpec/ReturnFromStub` on empty block. ([@yevhene]) -- Add `RSpec/ContextWording` cop. ([@pirj], [@telmofcosta]) -- Fix `RSpec/SubjectStub` cop matches receive message inside all matcher. ([@walf443]) - -## 1.19.0 (2017-10-18) - -Compatibility release so users can upgrade RuboCop to 0.51.0. No new features. - -## 1.18.0 (2017-09-29) - -- Fix false positive in `Capybara/FeatureMethods`. ([@Darhazer]) -- Add `RSpec/Capybara/CurrentPathExpectation` cop for feature specs, disallowing setting expectations on `current_path`. ([@timrogers]) -- Fix false positive in `RSpec/LetBeforeExamples` cop when example group contains single let. ([@Darhazer]) - -## 1.17.1 (2017-09-20) - -- Improved `RSpec/ReturnFromStub` to handle string interpolation, hashes and do..end blocks. ([@Darhazer]) -- Fixed compatibility with JRuby. ([@zverok]) - -## 1.17.0 (2017-09-14) - -- Add `RSpec/Capybara` namespace including the first cop for feature specs: `Capybara/FeatureMethods`. ([@rspeicher]) -- Update to RuboCop 0.50.0. ([@bquorning]) - -## 1.16.0 (2017-09-06) - -- Add `RSpec/FactoryGirl` namespace including the first cop for factories: `FactoryGirl/DynamicAttributeDefinedStatically`. ([@jonatas]) -- Add disabled by default `RSpec/AlignLeftLetBrace`. ([@backus]) -- Add disabled by default `RSpec/AlignRightLetBrace`. ([@backus]) -- Add `RSpec/LetBeforeExamples` cop. ([@Darhazer]) -- Add `RSpec/MultipleSubjects` cop. ([@backus]) -- Add `RSpec/ReturnFromStub` cop. ([@Darhazer]) -- Add `RSpec/VoidExpect` cop. ([@pocke]) -- Add `RSpec/InvalidPredicateMatcher` cop. ([@pocke]) -- Change HookArgument cop to detect when hook has a receiver. ([@pocke]) -- Add `RSpec/PredicateMatcher` cop. ([@pocke]) -- Add `RSpec/ExpectInHook` cop. ([@pocke]) -- `RSpec/MultipleExpectations` now detects usage of expect_any_instance_of. ([@Darhazer]) -- `RSpec/MultipleExpectations` now detects usage of is_expected. ([@bmorrall]) - -## 1.15.1 (2017-04-30) - -- Fix the handling of various edge cases in the `RSpec/ExampleWording` cop, including one that would cause autocorrect to crash. ([@dgollahon]) -- Fix `RSpec/IteratedExpectation` crashing when there is an assignment in the iteration. ([@Darhazer]) -- Fix false positive in `RSpec/SingleArgumentMessageChain` cop when the single argument is a hash. ([@Darhazer]) - -## 1.15.0 (2017-03-24) - -- Add `RSpec/DescribeSymbol` cop. ([@rspeicher]) -- Fix error when `RSpec/OverwritingSetup` and `RSpec/ScatteredLet` analyzed empty example groups. ([@backus]) - -## 1.14.0 (2017-03-24) - -- Add `RSpec/OverwritingSetup` cop. ([@Darhazer]) -- Add autocorrect support for `RSpec/LeadingSubject` cop. ([@Darhazer]) -- Add `RSpec/ScatteredLet` cop. ([@Darhazer]) -- Add `RSpec/IteratedExpectation` cop. ([@Darhazer]) -- Add `RSpec/EmptyLineAfterSubject` cop. ([@Darhazer]) -- Add `RSpec/EmptyLineAfterFinalLet` cop. ([@Darhazer]) - -## 1.13.0 (2017-03-07) - -- Add repeated 'it' detection to `RSpec/ExampleWording` cop. ([@dgollahon]) -- Add \[observed_nesting/max_nesting\] info to `RSpec/NestedGroups` messages. ([@dgollahon]) -- Add `RSpec/ItBehavesLike` cop. ([@dgollahon]) -- Add `RSpec/SharedContext` cop. ([@Darhazer]) -- `RSpec/MultipleExpectations`: Count aggregate_failures block as single expectation. ([@Darhazer]) -- Fix `ExpectActual` cop flagging `rspec-rails` routing specs. ([@backus]) -- Fix `FilePath` cop not registering offenses for files like `spec/blog/user.rb` when it should be `spec/blog/user_spec.rb`. ([@backus]) - -## 1.12.0 (2017-02-21) - -- Add `RSpec/InstanceSpy` cop. ([@Darhazer]) -- Add `RSpec/BeforeAfterAll` for avoiding leaky global test setup. ([@cfabianski]) - -## 1.11.0 (2017-02-16) - -- Add `AroundBlock` cop. ([@Darhazer]) -- Add `EnforcedStyle` configuration for `RSpec/DescribedClass` cop. ([@Darhazer]) -- Fix false positive for `RSpec/RepeatedExample` cop. ([@redross]) - -## 1.10.0 (2017-01-15) - -- Fix false negative for `RSpec/MessageSpies` cop. ([@onk]) -- Fix internal dependencies on RuboCop to be compatible with 0.47 release. ([@backus]) -- Add autocorrect support for `SingleArgumentMessageChain` cop. ([@bquorning]) -- Rename `NestedGroups`' configuration key from `MaxNesting` to `Max` in order to be consistent with other cop configuration. ([@backus]) -- Add `RepeatedExample` cop for detecting repeated examples within example groups. ([@backus]) -- Add `ScatteredSetup` cop for enforcing that only one `before`, `around`, and `after` hook are used per example group scope. ([@backus]) -- Add `ExpectOutput` cop for recommending `expect { ... }.to output(...).to_stdout`. ([@backus]) - -## 1.9.1 (2017-01-02) - -- Fix unintentional regression change in `NestedGroups` reported in #270. ([@backus]) -- Change `MaxNesting` for `NestedGroups` from 2 to 3. ([@backus]) - -## 1.9.0 (2016-12-29) - -- Add `MessageSpies` cop for enforcing consistent style of either `expect(...).to have_received` or `expect(...).to receive`, intended as a replacement for the `MessageExpectation` cop. ([@bquorning]) -- Fix `DescribeClass` to not flag `describe` at the top of a block of shared examples. ([@clupprich]) -- Add `SingleArgumentMessageChain` cop for recommending use of `receive` instead of `receive_message_chain` where possible. ([@bquorning]) -- Add `RepeatedDescription` cop for detecting repeated example descriptions within example groups. ([@backus]) - -## 1.8.0 (2016-10-27) - -- Optionally ignore method names in the `describe` argument when running the `FilePath` cop. ([@bquorning]) -- Fix regression in how `FilePath` converts alphanumeric class names into paths. ([@bquorning]) -- Add `ImplicitExpect` cop for enforcing `should` vs. `is_expected.to`. ([@backus]) -- Disable `MessageExpectation` cop in the default configuration. ([@bquorning]) - -## 1.7.0 (2016-08-24) - -- Add support for checking all example groups with `ExampleLength`. ([@backus]) -- Add support for checking shared example groups for `DescribedClass`. ([@backus]) -- Add support for checking `its` from [rspec-its](https://github.com/rspec/rspec-its). ([@backus]) -- Add `EmptyExampleGroup` cop for detecting `describe`s and `context`s without any tests inside. ([@backus]) -- Add `CustomIncludeMethods` configuration option for `EmptyExampleGroup`. ([@backus]) -- Add `NestedGroups` cop for detecting excessive example group nesting. ([@backus]) -- Add `MaxNesting` configuration option for `NestedGroups` cop. ([@backus]) -- Add `ExpectActual` cop for detecting literal values within `expect(...)`. ([@backus]) -- Add `MultipleExpectations` cop for detecting multiple `expect(...)` calls within one example. ([@backus]) -- Add `Max` configuration option for `MultipleExpectations`. ([@backus]) -- Add `SubjectStub` cop for testing stubbed test subjects. ([@backus]) -- Add `LetSetup` cop for detecting cases where `let!` is used for test setup. ([@backus]) -- Change all cops to only inspect files with names following rspec convention (`*/spec/*` and/or `_spec.rb`). ([@backus]) -- Add `AllCops/RSpec` configuration option for specifying custom spec file patterns. ([@backus]) -- Add `AssignmentOnly` configuration option for `RSpec/InstanceVariable` cop. ([@backus]) -- Add `BeEql` cop which looks for expectations that can use `be(...)` instead of `eql(...)`. ([@backus]) -- Add autocorrect support for `BeEql` cop. ([@backus]) -- Add `MessageExpectation` cop for enforcing consistent style of either `expect(...).to receive` or `allow(...).to receive`. ([@backus]) -- Add `MessageChain` cop. ([@bquorning]) - -## 1.6.0 (2016-08-03) - -- Add `SkipBlocks` option for `DescribedClass` cop. ([@backus]) - -## 1.5.3 (2016-08-02) - -- Add `RSpec/NamedSubject` cop. ([@backus]) - -## 1.5.2 (2016-08-01) - -- Drop support for ruby `2.0.0` and `2.1.0`. ([@backus]) -- Internal refactorings and improved test coverage. ([@backus]) - -## 1.5.1 (2016-07-20) - -- Fix `unrecognized parameter RSpec/VerifiedDoubles:IgnoreSymbolicNames` warning. ([@jeffreyc]) -- Update to rubocop 0.41.2. ([@backus]) - -## 1.5.0 (2016-05-17) - -- Expand `VerifiedDoubles` cop to check for `spy` as well as `double`. ([@andyw8]) -- Enable `VerifiedDoubles` cop by default. ([@andyw8]) -- Add `IgnoreSymbolicNames` option for `VerifiedDoubles` cop. ([@andyw8]) -- Add `RSpec::ExampleLength` cop. ([@andyw8]) -- Handle alphanumeric class names in `FilePath` cop. ([@andyw8]) -- Skip `DescribeClass` cop for view specs. ([@andyw8]) -- Skip `FilePath` cop for Rails routing specs. ([@andyw8]) -- Add cop to check for focused specs. ([@renanborgescampos], [@jaredmoody]) -- Clean-up `RSpec::NotToNot` to use same configuration semantics as other RuboCop cops, add autocorrect support for `RSpec::NotToNot`. ([@baberthal]) -- Update to rubocop 0.40.0. ([@nijikon]) - -## 1.4.1 (2016-04-03) - -- Ignore routing specs for DescribeClass cop. ([@nijikon]) -- Move rubocop dependency to runtime. ([@nijikon]) -- Update to rubocop 0.39.0. ([@nijikon]) - -## 1.4.0 (2016-02-15) - -- Update to rubocop 0.37.2. ([@nijikon]) -- Update ruby versions we test against. ([@nijikon]) -- Add `RSpec::NotToNot` cop. ([@miguelfteixeira]) -- Add `RSpec/AnyInstance` cop. ([@mlarraz]) - -## 1.3.1 - -- Fix auto correction issue - syntax had changed in RuboCop v0.31. ([@bquorning]) -- Add RuboCop clone to vendor folder - see #39 for details. ([@bquorning]) - -## 1.3.0 - -- Ignore non string arguments for FilePathCop - thanks to @deivid-rodriguez. ([@geniou]) -- Skip DescribeMethod cop for tagged specs. ([@deivid-rodriguez]) -- Skip DescribeClass cop for feature/request specs. ([@deivid-rodriguez]) - -## 1.2.2 - -- Make `RSpec::ExampleWording` case insensitive. ([@geniou]) - -## 1.2.1 - -- Add `RSpec::VerifiedDoubles` cop. ([@andyw8]) - -## 1.2.0 - -- Drop support of ruby `1.9.2`. ([@geniou]) -- Update to RuboCop `~> 0.24`. ([@geniou]) -- Add `autocorrect` to `RSpec::ExampleWording`. This experimental - use with care and check the changes. ([@geniou]) -- Fix config loader debug output. ([@geniou]) -- Rename `FileName` cop to `FilePath` as a workaround - see [#19](https://github.com/nevir/rubocop-rspec/issues/19). ([@geniou]) - -## 1.1.0 - -- Add `autocorrect` to `RSpec::DescribedClass` cop. ([@geniou]) - -## 1.0.1 - -- Add `config` folder to gemspec. ([@pstengel]) - -## 1.0.rc3 - -- Update to RuboCop `>= 0.23`. ([@geniou]) -- Add configuration option for `CustomTransformation` to `FileName` cop. ([@geniou]) - -## 1.0.rc2 - -- Gem is no longer 20MB (sorry!). ([@nevir]) -- `RspecFileName` cop allows for method specs to organized into directories by class and type. ([@nevir]) - -## 1.0.rc1 - -- Update code to work with rubocop `>= 0.19`. ([@geniou]) -- Split `UnitSpecNaming` cop into `RSpecDescribeClass`, `RSpecDescribeMethod` and `RSpecFileName` and enabled them all by default. ([@geniou]) -- Add `RSpecExampleWording` cop to prevent to use of should at the beginning of the spec description. ([@geniou]) -- Fix `RSpecFileName` cop for non-class specs. ([@geniou]) -- Adapt `RSpecFileName` cop to common naming convention and skip spec with multiple top level describes. ([@geniou]) -- Add `RSpecMultipleDescribes` cop to check for multiple top level describes. ([@geniou]) -- Add `RSpecDescribedClass` to promote the use of `described_class`. ([@geniou]) -- Add `RSpecInstanceVariable` cop to check for the usage of instance variables. ([@geniou]) -[@abrom]: https://github.com/abrom -[@ahukkanen]: https://github.com/ahukkanen [@akiomik]: https://github.com/akiomik -[@akrox58]: https://github.com/akrox58 -[@alexwayfer]: https://github.com/AlexWayfer -[@andrykonchin]: https://github.com/andrykonchin -[@andyw8]: https://github.com/andyw8 [@anthony-robin]: https://github.com/anthony-robin -[@aried3r]: https://github.com/aried3r -[@baberthal]: https://github.com/baberthal -[@backus]: https://github.com/backus -[@bcgraham]: https://github.com/bcgraham -[@biinari]: https://github.com/biinari -[@bmorrall]: https://github.com/bmorrall [@bquorning]: https://github.com/bquorning -[@brentwheeldon]: https://github.com/BrentWheeldon -[@brianhawley]: https://github.com/BrianHawley -[@cfabianski]: https://github.com/cfabianski -[@clupprich]: https://github.com/clupprich -[@composerinteralia]: https://github.com/composerinteralia [@corydiamand]: https://github.com/corydiamand -[@darhazer]: https://github.com/Darhazer -[@daveworth]: https://github.com/daveworth -[@dduugg]: https://github.com/dduugg -[@deivid-rodriguez]: https://github.com/deivid-rodriguez -[@dgollahon]: https://github.com/dgollahon -[@dmitrytsepelev]: https://github.com/dmitrytsepelev -[@drcapulet]: https://github.com/drcapulet -[@drowze]: https://github.com/Drowze -[@dswij]: https://github.com/dswij -[@dvandersluis]: https://github.com/dvandersluis -[@edgibbs]: https://github.com/edgibbs -[@eikes]: https://github.com/eikes -[@eitoball]: https://github.com/eitoball -[@elebow]: https://github.com/elebow -[@elisefitz15]: https://github.com/EliseFitz15 -[@elliterate]: https://github.com/elliterate -[@faucct]: https://github.com/faucct -[@foton]: https://github.com/foton -[@francois-ferrandis]: https://github.com/francois-ferrandis -[@franzliedke]: https://github.com/franzliedke [@g-rath]: https://github.com/G-Rath -[@geniou]: https://github.com/geniou -[@gsamokovarov]: https://github.com/gsamokovarov -[@harry-graham]: https://github.com/harry-graham -[@harrylewis]: https://github.com/harrylewis -[@hosamaly]: https://github.com/hosamaly -[@ignaciovillaverde]: https://github.com/ignaciovillaverde -[@jaredbeck]: https://github.com/jaredbeck -[@jaredmoody]: https://github.com/jaredmoody -[@jdufresne]: https://github.com/jdufresne -[@jeffreyc]: https://github.com/jeffreyc -[@jessieay]: https://github.com/jessieay -[@jfragoulis]: https://github.com/jfragoulis -[@johnny-miyake]: https://github.com/johnny-miyake [@jojos003]: https://github.com/jojos003 -[@jonatas]: https://github.com/jonatas -[@jtannas]: https://github.com/jtannas -[@kellysutton]: https://github.com/kellysutton -[@koic]: https://github.com/koic -[@kuahyeow]: https://github.com/kuahyeow -[@lazycoder9]: https://github.com/lazycoder9 -[@leoarnold]: https://github.com/leoarnold -[@liberatys]: https://github.com/Liberatys -[@lokhi]: https://github.com/lokhi -[@luke-hill]: https://github.com/luke-hill -[@m-yamashita01]: https://github.com/M-Yamashita01 -[@marocchino]: https://github.com/marocchino -[@miguelfteixeira]: https://github.com/miguelfteixeira -[@mkenyon]: https://github.com/mkenyon -[@mkrawc]: https://github.com/mkrawc -[@mlarraz]: https://github.com/mlarraz -[@mockdeep]: https://github.com/mockdeep [@mothonmars]: https://github.com/MothOnMars [@mvz]: https://github.com/mvz -[@naveg]: https://github.com/naveg -[@nc-holodakg]: https://github.com/nc-holodakg -[@nevir]: https://github.com/nevir -[@ngouy]: https://github.com/ngouy -[@nickcampbell18]: https://github.com/nickcampbell18 -[@nijikon]: https://github.com/nijikon -[@onk]: https://github.com/onk -[@onumis]: https://github.com/onumis -[@oshiro3]: https://github.com/oshiro3 -[@patrickomatic]: https://github.com/patrickomatic [@paydaylight]: https://github.com/paydaylight -[@philcoggins]: https://github.com/PhilCoggins [@pirj]: https://github.com/pirj -[@pocke]: https://github.com/pocke -[@pstengel]: https://github.com/pstengel -[@qqism]: https://github.com/QQism [@r7kamura]: https://github.com/r7kamura -[@rafix02]: https://github.com/Rafix02 -[@redross]: https://github.com/redross -[@renanborgescampos]: https://github.com/renanborgescampos -[@robinaugh]: https://github.com/robinaugh -[@robotdana]: https://github.com/robotdana -[@rolfschmidt]: https://github.com/rolfschmidt -[@rrosenblum]: https://github.com/rrosenblum -[@rspeicher]: https://github.com/rspeicher -[@rst-j]: https://github.com/RST-J -[@samrjenkins]: https://github.com/samrjenkins -[@schmijos]: https://github.com/schmijos -[@seanpdoyle]: https://github.com/seanpdoyle -[@sl4vr]: https://github.com/sl4vr -[@smcgivern]: https://github.com/smcgivern [@splattael]: https://github.com/splattael -[@stephannv]: https://github.com/stephannv -[@swelther]: https://github.com/swelther -[@t3h2mas]: https://github.com/t3h2mas -[@tdeo]: https://github.com/tdeo -[@tejasbubane]: https://github.com/tejasbubane -[@telmofcosta]: https://github.com/telmofcosta -[@tietew]: https://github.com/Tietew -[@timrogers]: https://github.com/timrogers [@tmaier]: https://github.com/tmaier -[@topalovic]: https://github.com/topalovic -[@twalpole]: https://github.com/twalpole -[@vzvu3k6k]: https://github.com/vzvu3k6k -[@walf443]: https://github.com/walf443 -[@ybiquitous]: https://github.com/ybiquitous [@ydah]: https://github.com/ydah -[@yevhene]: https://github.com/yevhene -[@ypresto]: https://github.com/ypresto -[@zdennis]: https://github.com/zdennis -[@zverok]: https://github.com/zverok diff --git a/README.md b/README.md index a29f7f24..34e5e217 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,29 @@ -# RuboCop RSpec +# RuboCop RSpec Rails [![Join the chat at https://gitter.im/rubocop-rspec/Lobby](https://badges.gitter.im/rubocop-rspec/Lobby.svg)](https://gitter.im/rubocop-rspec/Lobby) -[![Gem Version](https://badge.fury.io/rb/rubocop-rspec.svg)](https://rubygems.org/gems/rubocop-rspec) -![CI](https://github.com/rubocop/rubocop-rspec/workflows/CI/badge.svg) +[![Gem Version](https://badge.fury.io/rb/rubocop-rspec_rails.svg)](https://rubygems.org/gems/rubocop-rspec_rails) +![CI](https://github.com/rubocop/rubocop-rspec_rails/workflows/CI/badge.svg) -[RSpec](https://rspec.info/)-specific analysis for your projects, as an extension to +[RSpec Rails](https://rspec.info/)-specific analysis for your projects, as an extension to [RuboCop](https://github.com/rubocop/rubocop). ## Installation -Just install the `rubocop-rspec` gem +Just install the `rubocop-rspec_rails` gem ```bash -gem install rubocop-rspec +gem install rubocop-rspec_rails ``` or if you use bundler put this in your `Gemfile` ```ruby -gem 'rubocop-rspec', require: false +gem 'rubocop-rspec_rails', require: false ``` -### Upgrading to RuboCop RSpec v2.x - -Read all the details in our [Upgrade to Version 2.x](https://docs.rubocop.org/rubocop-rspec/2.0/upgrade_to_version_2.html) document. - ## Usage -You need to tell RuboCop to load the RSpec extension. There are three +You need to tell RuboCop to load the RSpec Rails extension. There are three ways to do this: ### RuboCop configuration file @@ -35,53 +31,49 @@ ways to do this: Put this into your `.rubocop.yml`. ```yaml -require: rubocop-rspec +require: rubocop-rspec_rails ``` Alternatively, use the following array notation when specifying multiple extensions. ```yaml require: - - rubocop-other-extension - rubocop-rspec + - rubocop-rspec_rails ``` -Now you can run `rubocop` and it will automatically load the RuboCop RSpec +Now you can run `rubocop` and it will automatically load the RuboCop RSpec Rails cops together with the standard cops. ### Command line ```bash -rubocop --require rubocop-rspec +rubocop --require rubocop-rspec_rails ``` ### Rake task ```ruby RuboCop::RakeTask.new do |task| - task.requires << 'rubocop-rspec' + task.requires << 'rubocop-rspec_rails' end ``` -### Code Climate - -rubocop-rspec is available on Code Climate as part of the rubocop engine. [Learn More](https://marketing.codeclimate.com/changelog/55a433bbe30ba00852000fac/). - ## Documentation -You can read more about RuboCop RSpec in its [official manual](https://docs.rubocop.org/rubocop-rspec). +You can read more about RuboCop RSpec Rails in its [official manual](https://docs.rubocop.org/rubocop-rspec_rails). ## The Cops All cops are located under -[`lib/rubocop/cop/rspec`](lib/rubocop/cop/rspec), and contain +[`lib/rubocop/cop/rspec_rails`](lib/rubocop/cop/rspec_rails), and contain examples/documentation. -In your `.rubocop.yml`, you may treat the RSpec cops just like any other +In your `.rubocop.yml`, you may treat the RSpec Rails cops just like any other cop. For example: ```yaml -RSpec/FilePath: +RSpecRails/AvoidSetupHook: Exclude: - spec/my_poorly_named_spec_file.rb ``` @@ -92,5 +84,5 @@ Checkout the [contribution guidelines](.github/CONTRIBUTING.md). ## License -`rubocop-rspec` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for +`rubocop-rspec_rails` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for the full text. diff --git a/Rakefile b/Rakefile index c11b55cd..d4c34f14 100644 --- a/Rakefile +++ b/Rakefile @@ -29,23 +29,18 @@ desc 'Build config/default.yml' task :build_config do require 'yard' - require 'rubocop-rspec' - require 'rubocop/rspec/config_formatter' - require 'rubocop/rspec/description_extractor' - - glob = File.join('lib', 'rubocop', 'cop', 'rspec', - '{,capybara,factory_bot,rails}', '*.rb') - # Due to YARD's sensitivity to file require order (as of 0.9.25), - # we have to prepend the list with our base cop, RuboCop::Cop::RSpec::Base. - # Otherwise, cop's parent class for cops loaded before our base cop class - # are detected as RuboCop::Cop::Base, and that complicates the detection - # of their relation with RuboCop RSpec. - rspec_cop_path = File.join('lib', 'rubocop', 'cop', 'rspec', 'base.rb') + require 'rubocop-rspec_rails' + require 'rubocop/rspec_rails/config_formatter' + require 'rubocop/rspec_rails/description_extractor' + + glob = File.join('lib', 'rubocop', 'cop', 'rspec_rails', '*.rb') YARD::Tags::Library.define_tag('Cop Safety Information', :safety) - YARD.parse(Dir[glob].prepend(rspec_cop_path), []) + YARD.parse(Dir[glob], []) descriptions = - RuboCop::RSpec::DescriptionExtractor.new(YARD::Registry.all(:class)).to_h + RuboCop::RSpecRails::DescriptionExtractor.new( + YARD::Registry.all(:class) + ).to_h current_config = if Psych::VERSION >= '4.0.0' # RUBY_VERSION >= '3.1.0' YAML.unsafe_load_file('config/default.yml') else @@ -54,7 +49,9 @@ task :build_config do File.write( 'config/default.yml', - RuboCop::RSpec::ConfigFormatter.new(current_config, descriptions).dump + RuboCop::RSpecRails::ConfigFormatter.new( + current_config, descriptions + ).dump ) end @@ -100,7 +97,9 @@ task :new_cop, [:cop] do |_task, args| generator = RuboCop::Cop::Generator.new(cop_name) generator.write_source generator.write_spec - generator.inject_require(root_file_path: 'lib/rubocop/cop/rspec_cops.rb') + generator.inject_require( + root_file_path: 'lib/rubocop/cop/rspec_rails_cops.rb' + ) generator.inject_config puts generator.todo diff --git a/config/default.yml b/config/default.yml index 7a0fc924..bc3fe0e5 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1,1143 +1,18 @@ --- -RSpec: - Enabled: true - StyleGuideBaseURL: https://rspec.rubystyle.guide - DocumentationBaseURL: https://docs.rubocop.org/rubocop-rspec - Include: &1 - - "**/*_spec.rb" - - "**/spec/**/*" - Language: &2 - inherit_mode: - merge: - - Expectations - - Helpers - - Hooks - - Subjects - ExampleGroups: - inherit_mode: - merge: - - Regular - - Skipped - - Focused - Regular: - - describe - - context - - feature - - example_group - Skipped: - - xdescribe - - xcontext - - xfeature - Focused: - - fdescribe - - fcontext - - ffeature - Examples: - inherit_mode: - merge: - - Regular - - Skipped - - Focused - - Pending - Regular: - - it - - specify - - example - - scenario - - its - Focused: - - fit - - fspecify - - fexample - - fscenario - - focus - Skipped: - - xit - - xspecify - - xexample - - xscenario - - skip - Pending: - - pending - Expectations: - - are_expected - - expect - - expect_any_instance_of - - is_expected - - should - - should_not - - should_not_receive - - should_receive - Helpers: - - let - - let! - Hooks: - - prepend_before - - before - - append_before - - around - - prepend_after - - after - - append_after - Includes: - inherit_mode: - merge: - - Examples - - Context - Examples: - - it_behaves_like - - it_should_behave_like - - include_examples - Context: - - include_context - SharedGroups: - inherit_mode: - merge: - - Examples - - Context - Examples: - - shared_examples - - shared_examples_for - Context: - - shared_context - Subjects: - - subject - - subject! - -Metrics/BlockLength: - inherit_mode: - merge: - - Exclude - Exclude: - - "**/*_spec.rb" - - "**/spec/**/*" - -RSpec/AlignLeftLetBrace: - Description: Checks that left braces for adjacent single line lets are aligned. - Enabled: false - VersionAdded: '1.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignLeftLetBrace - -RSpec/AlignRightLetBrace: - Description: Checks that right braces for adjacent single line lets are aligned. - Enabled: false - VersionAdded: '1.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AlignRightLetBrace - -RSpec/AnyInstance: - Description: Check that instances are not being stubbed globally. - Enabled: true - VersionAdded: '1.4' - StyleGuide: https://rspec.rubystyle.guide/#any_instance_of - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AnyInstance - -RSpec/AroundBlock: - Description: Checks that around blocks actually run the test. - Enabled: true - VersionAdded: '1.11' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/AroundBlock - -RSpec/Be: - Description: Check for expectations where `be` is used without argument. - Enabled: true - VersionAdded: '1.25' - StyleGuide: https://rspec.rubystyle.guide/#be-matcher - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Be - -RSpec/BeEmpty: - Description: Prefer using `be_empty` when checking for an empty array. - Enabled: pending - VersionAdded: '2.20' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEmpty - -RSpec/BeEq: - Description: Check for expectations where `be(...)` can replace `eq(...)`. - Enabled: pending - Safe: false - VersionAdded: 2.9.0 - VersionChanged: '2.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEq - -RSpec/BeEql: - Description: Check for expectations where `be(...)` can replace `eql(...)`. - Enabled: true - Safe: false - VersionAdded: '1.7' - VersionChanged: '2.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql - -RSpec/BeNil: - Description: Ensures a consistent style is used when matching `nil`. - Enabled: pending - EnforcedStyle: be_nil - SupportedStyles: - - be - - be_nil - VersionAdded: 2.9.0 - VersionChanged: 2.10.0 - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil - -RSpec/BeforeAfterAll: - Description: Check that before/after(:all/:context) isn't being used. - Enabled: true - Exclude: - - "**/spec/spec_helper.rb" - - "**/spec/rails_helper.rb" - - "**/spec/support/**/*.rb" - VersionAdded: '1.12' - VersionChanged: '2.23' - StyleGuide: https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll - -RSpec/ChangeByZero: - Description: Prefer negated matchers over `to change.by(0)`. - Enabled: pending - VersionAdded: '2.11' - VersionChanged: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ChangeByZero - NegatedMatcher: ~ - -RSpec/ClassCheck: - Description: Enforces consistent use of `be_a` or `be_kind_of`. - StyleGuide: "#is-a-vs-kind-of" - Enabled: pending - VersionAdded: '2.13' - EnforcedStyle: be_a - SupportedStyles: - - be_a - - be_kind_of - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ClassCheck - -RSpec/ContainExactly: - Description: Checks where `contain_exactly` is used. - Enabled: pending - VersionAdded: '2.19' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContainExactly - -RSpec/ContextMethod: - Description: "`context` should not be used for specifying methods." - Enabled: true - VersionAdded: '1.36' - StyleGuide: https://rspec.rubystyle.guide/#example-group-naming - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextMethod - -RSpec/ContextWording: - Description: Checks that `context` docstring starts with an allowed prefix. - Enabled: true - Prefixes: - - when - - with - - without - AllowedPatterns: [] - VersionAdded: '1.20' - VersionChanged: '2.13' - StyleGuide: https://rspec.rubystyle.guide/#context-descriptions - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ContextWording - -RSpec/DescribeClass: - Description: Check that the first argument to the top-level describe is a constant. - Enabled: true - Exclude: - - "**/spec/features/**/*" - - "**/spec/requests/**/*" - - "**/spec/routing/**/*" - - "**/spec/system/**/*" - - "**/spec/views/**/*" - IgnoredMetadata: - type: - - channel - - controller - - helper - - job - - mailer - - model - - request - - routing - - view - - feature - - system - - mailbox - - aruba - - task - VersionAdded: '1.0' - VersionChanged: '2.7' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass - -RSpec/DescribeMethod: - Description: Checks that the second argument to `describe` specifies a method. - Enabled: true - VersionAdded: '1.0' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeMethod - -RSpec/DescribeSymbol: - Description: Avoid describing symbols. - Enabled: true - VersionAdded: '1.15' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeSymbol - -RSpec/DescribedClass: - Description: Checks that tests use `described_class`. - Enabled: true - SkipBlocks: false - EnforcedStyle: described_class - SupportedStyles: - - described_class - - explicit - OnlyStaticConstants: true - SafeAutoCorrect: false - VersionAdded: '1.0' - VersionChanged: '2.27' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass - -RSpec/DescribedClassModuleWrapping: - Description: Avoid opening modules and defining specs within them. - Enabled: false - VersionAdded: '1.37' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClassModuleWrapping - -RSpec/Dialect: - Description: Enforces custom RSpec dialects. - Enabled: false - PreferredMethods: {} - VersionAdded: '1.33' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect - -RSpec/DuplicatedMetadata: - Description: Avoid duplicated metadata. - Enabled: pending - VersionAdded: '2.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DuplicatedMetadata - -RSpec/EmptyExampleGroup: - Description: Checks if an example group does not include any tests. - Enabled: true - SafeAutoCorrect: false - VersionAdded: '1.7' - VersionChanged: '2.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup - -RSpec/EmptyHook: - Description: Checks for empty before and after hooks. - Enabled: true - VersionAdded: '1.39' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyHook - -RSpec/EmptyLineAfterExample: - Description: Checks if there is an empty line after example blocks. - Enabled: true - AllowConsecutiveOneLiners: true - VersionAdded: '1.36' - StyleGuide: https://rspec.rubystyle.guide/#empty-lines-around-examples - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample - -RSpec/EmptyLineAfterExampleGroup: - Description: Checks if there is an empty line after example group blocks. - Enabled: true - VersionAdded: '1.27' - StyleGuide: https://rspec.rubystyle.guide/#empty-lines-between-describes - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExampleGroup - -RSpec/EmptyLineAfterFinalLet: - Description: Checks if there is an empty line after the last let block. - Enabled: true - VersionAdded: '1.14' - StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet - -RSpec/EmptyLineAfterHook: - Description: Checks if there is an empty line after hook blocks. - Enabled: true - VersionAdded: '1.27' - VersionChanged: '2.13' - StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterHook - AllowConsecutiveOneLiners: true - -RSpec/EmptyLineAfterSubject: - Description: Checks if there is an empty line after subject block. - Enabled: true - VersionAdded: '1.14' - StyleGuide: https://rspec.rubystyle.guide/#empty-line-after-let - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterSubject - -RSpec/EmptyMetadata: - Description: Avoid empty metadata hash. - Enabled: pending - VersionAdded: '2.24' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyMetadata - -RSpec/Eq: - Description: Use `eq` instead of `be ==` to compare objects. - Enabled: pending - VersionAdded: '2.24' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Eq - -RSpec/ExampleLength: - Description: Checks for long examples. - Enabled: true - Max: 5 - CountAsOne: [] - VersionAdded: '1.5' - VersionChanged: '2.3' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleLength - -RSpec/ExampleWithoutDescription: - Description: Checks for examples without a description. - Enabled: true - EnforcedStyle: always_allow - SupportedStyles: - - always_allow - - single_line_only - - disallow - VersionAdded: '1.22' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription - -RSpec/ExampleWording: - Description: Checks for common mistakes in example descriptions. - Enabled: true - CustomTransform: - be: is - BE: IS - have: has - HAVE: HAS - IgnoredWords: [] - DisallowedExamples: - - works - VersionAdded: '1.0' - VersionChanged: '2.13' - StyleGuide: https://rspec.rubystyle.guide/#should-in-example-docstrings - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording - -RSpec/ExcessiveDocstringSpacing: - Description: Checks for excessive whitespace in example descriptions. - Enabled: pending - VersionAdded: '2.5' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExcessiveDocstringSpacing - -RSpec/ExpectActual: - Description: Checks for `expect(...)` calls containing literal values. - Enabled: true - Exclude: - - "**/spec/routing/**/*" - VersionAdded: '1.7' - VersionChanged: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectActual - -RSpec/ExpectChange: - Description: Checks for consistent style of change matcher. - Enabled: true - EnforcedStyle: method_call - SupportedStyles: - - method_call - - block - SafeAutoCorrect: false - VersionAdded: '1.22' - VersionChanged: '2.5' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange - -RSpec/ExpectInHook: - Description: Do not use `expect` in hooks such as `before`. - Enabled: true - VersionAdded: '1.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectInHook - -RSpec/ExpectOutput: - Description: Checks for opportunities to use `expect { ... }.to output`. - Enabled: true - VersionAdded: '1.10' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectOutput - -RSpec/FilePath: - Description: Checks that spec file paths are consistent and well-formed. - Enabled: true - Include: - - "**/*_spec*rb*" - - "**/spec/**/*" - CustomTransform: - RuboCop: rubocop - RSpec: rspec - IgnoreMethods: false - SpecSuffixOnly: false - VersionAdded: '1.2' - VersionChanged: '2.24' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath - -RSpec/Focus: - Description: Checks if examples are focused. - Enabled: true - VersionAdded: '1.5' - VersionChanged: '2.1' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus - -RSpec/HookArgument: - Description: Checks the arguments passed to `before`, `around`, and `after`. - Enabled: true - EnforcedStyle: implicit - SupportedStyles: - - implicit - - each - - example - VersionAdded: '1.7' - StyleGuide: https://rspec.rubystyle.guide/#redundant-beforeeach - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument - -RSpec/HooksBeforeExamples: - Description: Checks for before/around/after hooks that come after an example. - Enabled: true - VersionAdded: '1.29' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HooksBeforeExamples - -RSpec/IdenticalEqualityAssertion: - Description: Checks for equality assertions with identical expressions on both sides. - Enabled: pending - VersionAdded: '2.4' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IdenticalEqualityAssertion - -RSpec/ImplicitBlockExpectation: - Description: Check that implicit block expectation syntax is not used. - Enabled: true - VersionAdded: '1.35' - StyleGuide: https://rspec.rubystyle.guide/#implicit-block-expectations - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitBlockExpectation - -RSpec/ImplicitExpect: - Description: Check that a consistent implicit expectation style is used. - Enabled: true - EnforcedStyle: is_expected - SupportedStyles: - - is_expected - - should - VersionAdded: '1.8' - StyleGuide: https://rspec.rubystyle.guide/#use-expect - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitExpect - -RSpec/ImplicitSubject: - Description: Checks for usage of implicit subject (`is_expected` / `should`). - Enabled: true - EnforcedStyle: single_line_only - SupportedStyles: - - single_line_only - - single_statement_only - - disallow - - require_implicit - VersionAdded: '1.29' - VersionChanged: '2.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ImplicitSubject - -RSpec/IndexedLet: - Description: Do not set up test data using indexes (e.g., `item_1`, `item_2`). - Enabled: pending - VersionAdded: '2.20' - VersionChanged: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IndexedLet - Max: 1 - AllowedIdentifiers: [] - AllowedPatterns: [] - -RSpec/InstanceSpy: - Description: Checks for `instance_double` used with `have_received`. - Enabled: true - VersionAdded: '1.12' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceSpy - -RSpec/InstanceVariable: - Description: Checks for instance variable usage in specs. - Enabled: true - AssignmentOnly: false - VersionAdded: '1.0' - VersionChanged: '1.7' - StyleGuide: https://rspec.rubystyle.guide/#instance-variables - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable - -RSpec/IsExpectedSpecify: - Description: Check for `specify` with `is_expected` and one-liner expectations. - Enabled: pending - VersionAdded: '2.27' - StyleGuide: https://rspec.rubystyle.guide/#it-and-specify - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IsExpectedSpecify - -RSpec/ItBehavesLike: - Description: Checks that only one `it_behaves_like` style is used. - Enabled: true - EnforcedStyle: it_behaves_like - SupportedStyles: - - it_behaves_like - - it_should_behave_like - VersionAdded: '1.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ItBehavesLike - -RSpec/IteratedExpectation: - Description: Check that `all` matcher is used instead of iterating over an array. - Enabled: true - VersionAdded: '1.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/IteratedExpectation - -RSpec/LeadingSubject: - Description: Enforce that subject is the first definition in the test. - Enabled: true - VersionAdded: '1.7' - VersionChanged: '1.14' - StyleGuide: https://rspec.rubystyle.guide/#leading-subject - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject - -RSpec/LeakyConstantDeclaration: - Description: Checks that no class, module, or constant is declared. - Enabled: true - VersionAdded: '1.35' - StyleGuide: https://rspec.rubystyle.guide/#declare-constants - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeakyConstantDeclaration - -RSpec/LetBeforeExamples: - Description: Checks for `let` definitions that come after an example. - Enabled: true - VersionAdded: '1.16' - VersionChanged: '1.22' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples - -RSpec/LetSetup: - Description: Checks unreferenced `let!` calls being used for test setup. - Enabled: true - VersionAdded: '1.7' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetSetup - -RSpec/MatchArray: - Description: Checks where `match_array` is used. - Enabled: pending - VersionAdded: '2.19' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MatchArray - -RSpec/MessageChain: - Description: Check that chains of messages are not being stubbed. - Enabled: true - VersionAdded: '1.7' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageChain - -RSpec/MessageExpectation: - Description: Checks for consistent message expectation style. - Enabled: false - EnforcedStyle: allow - SupportedStyles: - - allow - - expect - VersionAdded: '1.7' - VersionChanged: '1.8' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageExpectation - -RSpec/MessageSpies: - Description: Checks that message expectations are set using spies. - Enabled: true - EnforcedStyle: have_received - SupportedStyles: - - have_received - - receive - VersionAdded: '1.9' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MessageSpies - -RSpec/MetadataStyle: - Description: Use consistent metadata style. - Enabled: pending - EnforcedStyle: symbol - SupportedStyles: - - hash - - symbol - VersionAdded: '2.24' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MetadataStyle - -RSpec/MissingExampleGroupArgument: - Description: Checks that the first argument to an example group is not empty. - Enabled: true - VersionAdded: '1.28' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MissingExampleGroupArgument - -RSpec/MultipleDescribes: - Description: Checks for multiple top-level example groups. - Enabled: true - VersionAdded: '1.0' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleDescribes - -RSpec/MultipleExpectations: - Description: Checks if examples contain too many `expect` calls. - Enabled: true - Max: 1 - VersionAdded: '1.7' - VersionChanged: '1.21' - StyleGuide: https://rspec.rubystyle.guide/#expectation-per-example - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleExpectations - -RSpec/MultipleMemoizedHelpers: - Description: Checks if example groups contain too many `let` and `subject` calls. - Enabled: true - AllowSubject: true - Max: 5 - VersionAdded: '1.43' - StyleGuide: https://rspec.rubystyle.guide/#let-blocks - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleMemoizedHelpers - -RSpec/MultipleSubjects: - Description: Checks if an example group defines `subject` multiple times. - Enabled: true - VersionAdded: '1.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/MultipleSubjects - -RSpec/NamedSubject: - Description: Checks for explicitly referenced test subjects. - Enabled: true - EnforcedStyle: always - SupportedStyles: - - always - - named_only - IgnoreSharedExamples: true - VersionAdded: 1.5.3 - VersionChanged: '2.15' - StyleGuide: https://rspec.rubystyle.guide/#use-subject - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NamedSubject - -RSpec/NestedGroups: - Description: Checks for nested example groups. - Enabled: true - Max: 3 - AllowedGroups: [] - VersionAdded: '1.7' - VersionChanged: '2.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NestedGroups - -RSpec/NoExpectationExample: - Description: Checks if an example contains any expectation. - Enabled: pending - Safe: false - VersionAdded: '2.13' - VersionChanged: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NoExpectationExample - AllowedPatterns: - - "^expect_" - - "^assert_" - -RSpec/NotToNot: - Description: Checks for consistent method usage for negating expectations. - Enabled: true - EnforcedStyle: not_to - SupportedStyles: - - not_to - - to_not - VersionAdded: '1.4' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NotToNot - -RSpec/OverwritingSetup: - Description: Checks if there is a let/subject that overwrites an existing one. - Enabled: true - VersionAdded: '1.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/OverwritingSetup - -RSpec/Pending: - Description: Checks for any pending or skipped examples. - Enabled: false - VersionAdded: '1.25' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Pending - -RSpec/PendingWithoutReason: - Description: Checks for pending or skipped examples without reason. - Enabled: pending - VersionAdded: '2.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PendingWithoutReason - -RSpec/PredicateMatcher: - Description: Prefer using predicate matcher over using predicate method directly. - Enabled: true - Strict: true - EnforcedStyle: inflected - AllowedExplicitMatchers: [] - SupportedStyles: - - inflected - - explicit - SafeAutoCorrect: false - VersionAdded: '1.16' - StyleGuide: https://rspec.rubystyle.guide/#predicate-matchers - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/PredicateMatcher - -RSpec/ReceiveCounts: - Description: Check for `once` and `twice` receive counts matchers usage. - Enabled: true - VersionAdded: '1.26' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveCounts - -RSpec/ReceiveMessages: - Description: Checks for multiple messages stubbed on the same object. - Enabled: pending - SafeAutoCorrect: false - VersionAdded: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveMessages - -RSpec/ReceiveNever: - Description: Prefer `not_to receive(...)` over `receive(...).never`. - Enabled: true - VersionAdded: '1.28' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReceiveNever - -RSpec/RedundantAround: - Description: Remove redundant `around` hook. - Enabled: pending - VersionAdded: '2.19' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantAround - -RSpec/RedundantPredicateMatcher: - Description: Checks for redundant predicate matcher. - Enabled: pending - VersionAdded: '2.26' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantPredicateMatcher - -RSpec/RemoveConst: - Description: Checks that `remove_const` is not used in specs. - Enabled: pending - VersionAdded: '2.26' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RemoveConst - -RSpec/RepeatedDescription: - Description: Check for repeated description strings in example groups. - Enabled: true - VersionAdded: '1.9' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedDescription - -RSpec/RepeatedExample: - Description: Check for repeated examples within example groups. - Enabled: true - VersionAdded: '1.10' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExample - -RSpec/RepeatedExampleGroupBody: - Description: Check for repeated describe and context block body. - Enabled: true - VersionAdded: '1.38' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupBody - -RSpec/RepeatedExampleGroupDescription: - Description: Check for repeated example group descriptions. - Enabled: true - VersionAdded: '1.38' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupDescription - -RSpec/RepeatedIncludeExample: - Description: Check for repeated include of shared examples. - Enabled: true - VersionAdded: '1.44' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedIncludeExample - -RSpec/RepeatedSubjectCall: - Description: Checks for repeated calls to subject missing that it is memoized. - Enabled: pending - VersionAdded: '2.27' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedSubjectCall - -RSpec/ReturnFromStub: - Description: Checks for consistent style of stub's return setting. - Enabled: true - EnforcedStyle: and_return - SupportedStyles: - - and_return - - block - VersionAdded: '1.16' - VersionChanged: '1.22' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ReturnFromStub - -RSpec/ScatteredLet: - Description: Checks for let scattered across the example group. - Enabled: true - VersionAdded: '1.14' - VersionChanged: '1.39' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet - -RSpec/ScatteredSetup: - Description: Checks for setup scattered across multiple hooks in an example group. - Enabled: true - VersionAdded: '1.10' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredSetup - -RSpec/SharedContext: - Description: Checks for proper shared_context and shared_examples usage. - Enabled: true - VersionAdded: '1.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedContext - -RSpec/SharedExamples: - Description: Checks for consistent style for shared example names. - Enabled: true - EnforcedStyle: string - SupportedStyles: - - string - - symbol - VersionAdded: '1.25' - VersionChanged: '2.26' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedExamples - -RSpec/SingleArgumentMessageChain: - Description: Checks that chains of messages contain more than one element. - Enabled: true - VersionAdded: '1.9' - VersionChanged: '1.10' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain - -RSpec/SkipBlockInsideExample: - Description: Checks for passing a block to `skip` within examples. - Enabled: pending - VersionAdded: '2.19' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SkipBlockInsideExample - -RSpec/SortMetadata: - Description: Sort RSpec metadata alphabetically. - Enabled: pending - VersionAdded: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SortMetadata - -RSpec/SpecFilePathFormat: - Description: Checks that spec file paths are consistent and well-formed. - Enabled: pending - Include: - - "**/*_spec.rb" - Exclude: - - "**/spec/routing/**/*" - CustomTransform: - RuboCop: rubocop - RSpec: rspec - IgnoreMethods: false - IgnoreMetadata: - type: routing - VersionAdded: '2.24' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathFormat - -RSpec/SpecFilePathSuffix: - Description: Checks that spec file paths suffix are consistent and well-formed. - Enabled: pending - VersionAdded: '2.24' - Include: - - "**/*_spec*rb*" - - "**/spec/**/*" - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix - -RSpec/StubbedMock: - Description: Checks that message expectations do not have a configured response. - Enabled: true - VersionAdded: '1.44' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock - -RSpec/SubjectDeclaration: - Description: Ensure that subject is defined using subject helper. - Enabled: pending - VersionAdded: '2.5' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectDeclaration - -RSpec/SubjectStub: - Description: Checks for stubbed test subjects. - Enabled: true - VersionAdded: '1.7' - VersionChanged: '2.8' - StyleGuide: https://rspec.rubystyle.guide/#dont-stub-subject - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectStub - -RSpec/UnspecifiedException: - Description: Checks for a specified error in checking raised errors. - Enabled: true - VersionAdded: '1.30' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/UnspecifiedException - -RSpec/VariableDefinition: - Description: Checks that memoized helpers names are symbols or strings. - Enabled: true - EnforcedStyle: symbols - SupportedStyles: - - symbols - - strings - VersionAdded: '1.40' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableDefinition - -RSpec/VariableName: - Description: Checks that memoized helper names use the configured style. - Enabled: true - EnforcedStyle: snake_case - SupportedStyles: - - snake_case - - camelCase - AllowedPatterns: [] - VersionAdded: '1.40' - VersionChanged: '2.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName - -RSpec/VerifiedDoubleReference: - Description: Checks for consistent verified double reference style. - Enabled: pending - SafeAutoCorrect: false - EnforcedStyle: constant - SupportedStyles: - - constant - - string - VersionAdded: 2.10.0 - VersionChanged: '2.12' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference - -RSpec/VerifiedDoubles: - Description: Prefer using verifying doubles over normal doubles. - Enabled: true - IgnoreNameless: true - IgnoreSymbolicNames: false - VersionAdded: 1.2.1 - VersionChanged: '1.5' - StyleGuide: https://rspec.rubystyle.guide/#doubles - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles - -RSpec/VoidExpect: - Description: Checks void `expect()`. - Enabled: true - VersionAdded: '1.16' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VoidExpect - -RSpec/Yield: - Description: Checks for calling a block within a stub. - Enabled: true - VersionAdded: '1.32' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Yield - -RSpec/Capybara: - Enabled: true - Include: *1 - Language: *2 - -RSpec/Capybara/CurrentPathExpectation: - Description: Checks that no expectations are set on Capybara's `current_path`. - Enabled: true - VersionAdded: '1.18' - VersionChanged: '2.0' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/CurrentPathExpectation - -RSpec/Capybara/FeatureMethods: - Description: Checks for consistent method usage in feature specs. - Enabled: true - EnabledMethods: [] - VersionAdded: '1.17' - VersionChanged: '2.0' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods - -RSpec/Capybara/MatchStyle: - Description: Checks for usage of deprecated style methods. - Enabled: pending - VersionAdded: '2.17' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/MatchStyle - -RSpec/Capybara/NegationMatcher: - Description: Enforces use of `have_no_*` or `not_to` for negated expectations. - Enabled: pending - VersionAdded: '2.14' - EnforcedStyle: not_to - SupportedStyles: - - have_no - - not_to - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/NegationMatcher - -RSpec/Capybara/SpecificActions: - Description: Checks for there is a more specific actions offered by Capybara. - Enabled: pending - VersionAdded: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificActions - -RSpec/Capybara/SpecificFinders: - Description: Checks if there is a more specific finder offered by Capybara. - Enabled: pending - VersionAdded: '2.13' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificFinders - -RSpec/Capybara/SpecificMatcher: - Description: Checks for there is a more specific matcher offered by Capybara. - Enabled: pending - VersionAdded: '2.12' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificMatcher - -RSpec/Capybara/VisibilityMatcher: - Description: Checks for boolean visibility in Capybara finders. - Enabled: true - VersionAdded: '1.39' - VersionChanged: '2.0' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher - -RSpec/FactoryBot: - Enabled: true - Include: *1 - Language: *2 - -RSpec/FactoryBot/AttributeDefinedStatically: - Description: Always declare attribute values as blocks. - Enabled: true - Include: - - "**/spec/factories.rb" - - "**/spec/factories/**/*.rb" - - "**/features/support/factories/**/*.rb" - VersionAdded: '1.28' - VersionChanged: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/AttributeDefinedStatically - -RSpec/FactoryBot/ConsistentParenthesesStyle: - Description: Use a consistent style for parentheses in factory bot calls. - Enabled: pending - EnforcedStyle: require_parentheses - SupportedStyles: - - require_parentheses - - omit_parentheses - VersionAdded: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/ConsistentParenthesesStyle - -RSpec/FactoryBot/CreateList: - Description: Checks for create_list usage. +RSpecRails: Enabled: true + DocumentationBaseURL: https://docs.rubocop.org/rubocop-rspec_rails Include: - "**/*_spec.rb" - "**/spec/**/*" - - "**/spec/factories.rb" - - "**/spec/factories/**/*.rb" - - "**/features/support/factories/**/*.rb" - EnforcedStyle: create_list - SupportedStyles: - - create_list - - n_times - VersionAdded: '1.25' - VersionChanged: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/CreateList - -RSpec/FactoryBot/FactoryClassName: - Description: Use string value when setting the class attribute explicitly. - Enabled: true - Include: - - "**/spec/factories.rb" - - "**/spec/factories/**/*.rb" - - "**/features/support/factories/**/*.rb" - VersionAdded: '1.37' - VersionChanged: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName - -RSpec/FactoryBot/FactoryNameStyle: - Description: Checks for name style for argument of FactoryBot::Syntax::Methods. - Enabled: pending - VersionAdded: '2.16' - EnforcedStyle: symbol - SupportedStyles: - - symbol - - string - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryNameStyle - -RSpec/FactoryBot/SyntaxMethods: - Description: Use shorthands from `FactoryBot::Syntax::Methods` in your specs. - Enabled: pending - SafeAutoCorrect: false - VersionAdded: '2.7' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/SyntaxMethods - -RSpec/Rails: - Enabled: true - Include: *1 - Language: *2 -RSpec/Rails/AvoidSetupHook: +RSpecRails/AvoidSetupHook: Description: Checks that tests use RSpec `before` hook over Rails `setup` method. Enabled: pending VersionAdded: '2.4' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/AvoidSetupHook -RSpec/Rails/HaveHttpStatus: +RSpecRails/HaveHttpStatus: Description: Checks that tests use `have_http_status` instead of equality matchers. Enabled: pending ResponseMethods: @@ -1146,9 +21,9 @@ RSpec/Rails/HaveHttpStatus: SafeAutoCorrect: false VersionAdded: '2.12' VersionChanged: '2.27' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HaveHttpStatus + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HaveHttpStatus -RSpec/Rails/HttpStatus: +RSpecRails/HttpStatus: Description: Enforces use of symbolic or numeric value to describe HTTP status. Enabled: true EnforcedStyle: symbolic @@ -1158,14 +33,14 @@ RSpec/Rails/HttpStatus: - be_status VersionAdded: '1.23' VersionChanged: '2.20' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatus -RSpec/Rails/InferredSpecType: +RSpecRails/InferredSpecType: Description: Identifies redundant spec type. Enabled: pending Safe: false VersionAdded: '2.14' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/InferredSpecType + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/InferredSpecType Inferences: channels: channel controllers: controller @@ -1183,13 +58,13 @@ RSpec/Rails/InferredSpecType: system: system views: view -RSpec/Rails/MinitestAssertions: +RSpecRails/MinitestAssertions: Description: Check if using Minitest-like matchers. Enabled: pending VersionAdded: '2.17' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/MinitestAssertions + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/MinitestAssertions -RSpec/Rails/NegationBeValid: +RSpecRails/NegationBeValid: Description: Enforces use of `be_invalid` or `not_to` for negated be_valid. Safe: false EnforcedStyle: not_to @@ -1198,11 +73,11 @@ RSpec/Rails/NegationBeValid: - be_invalid Enabled: pending VersionAdded: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/NegationBeValid -RSpec/Rails/TravelAround: +RSpecRails/TravelAround: Description: Prefer to travel in `before` rather than `around`. Enabled: pending Safe: false VersionAdded: '2.19' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/TravelAround + Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/TravelAround diff --git a/docs/antora.yml b/docs/antora.yml index 51a533a1..86387acc 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -1,5 +1,5 @@ -name: rubocop-rspec -title: RuboCop RSpec +name: rubocop-rspec_rails +title: RuboCop RSpec Rails version: ~ nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index db2d4198..511cf0d5 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -1,13 +1,7 @@ * xref:index.adoc[Home] * xref:installation.adoc[Installation] * xref:usage.adoc[Usage] -* xref:departments.adoc[Departments] * xref:cops.adoc[Cops] -* xref:upgrade_to_version_2.adoc[Upgrade to 2.x] -* xref:third_party_rspec_syntax_extensions.adoc[RSpec syntax extensions in third-party gems] * xref:development.adoc[Development] * Cops Documentation -** xref:cops_rspec_capybara.adoc[Capybara] -** xref:cops_rspec_factorybot.adoc[FactoryBot] ** xref:cops_rspec_rails.adoc[Rails] -** xref:cops_rspec.adoc[RSpec] diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 4dfed17f..b4fc11c6 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -1,143 +1,13 @@ // START_COP_LIST -=== Department xref:cops_rspec.adoc[RSpec] - -* xref:cops_rspec.adoc#rspecalignleftletbrace[RSpec/AlignLeftLetBrace] -* xref:cops_rspec.adoc#rspecalignrightletbrace[RSpec/AlignRightLetBrace] -* xref:cops_rspec.adoc#rspecanyinstance[RSpec/AnyInstance] -* xref:cops_rspec.adoc#rspecaroundblock[RSpec/AroundBlock] -* xref:cops_rspec.adoc#rspecbe[RSpec/Be] -* xref:cops_rspec.adoc#rspecbeempty[RSpec/BeEmpty] -* xref:cops_rspec.adoc#rspecbeeq[RSpec/BeEq] -* xref:cops_rspec.adoc#rspecbeeql[RSpec/BeEql] -* xref:cops_rspec.adoc#rspecbenil[RSpec/BeNil] -* xref:cops_rspec.adoc#rspecbeforeafterall[RSpec/BeforeAfterAll] -* xref:cops_rspec.adoc#rspecchangebyzero[RSpec/ChangeByZero] -* xref:cops_rspec.adoc#rspecclasscheck[RSpec/ClassCheck] -* xref:cops_rspec.adoc#rspeccontainexactly[RSpec/ContainExactly] -* xref:cops_rspec.adoc#rspeccontextmethod[RSpec/ContextMethod] -* xref:cops_rspec.adoc#rspeccontextwording[RSpec/ContextWording] -* xref:cops_rspec.adoc#rspecdescribeclass[RSpec/DescribeClass] -* xref:cops_rspec.adoc#rspecdescribemethod[RSpec/DescribeMethod] -* xref:cops_rspec.adoc#rspecdescribesymbol[RSpec/DescribeSymbol] -* xref:cops_rspec.adoc#rspecdescribedclass[RSpec/DescribedClass] -* xref:cops_rspec.adoc#rspecdescribedclassmodulewrapping[RSpec/DescribedClassModuleWrapping] -* xref:cops_rspec.adoc#rspecdialect[RSpec/Dialect] -* xref:cops_rspec.adoc#rspecduplicatedmetadata[RSpec/DuplicatedMetadata] -* xref:cops_rspec.adoc#rspecemptyexamplegroup[RSpec/EmptyExampleGroup] -* xref:cops_rspec.adoc#rspecemptyhook[RSpec/EmptyHook] -* xref:cops_rspec.adoc#rspecemptylineafterexample[RSpec/EmptyLineAfterExample] -* xref:cops_rspec.adoc#rspecemptylineafterexamplegroup[RSpec/EmptyLineAfterExampleGroup] -* xref:cops_rspec.adoc#rspecemptylineafterfinallet[RSpec/EmptyLineAfterFinalLet] -* xref:cops_rspec.adoc#rspecemptylineafterhook[RSpec/EmptyLineAfterHook] -* xref:cops_rspec.adoc#rspecemptylineaftersubject[RSpec/EmptyLineAfterSubject] -* xref:cops_rspec.adoc#rspecemptymetadata[RSpec/EmptyMetadata] -* xref:cops_rspec.adoc#rspeceq[RSpec/Eq] -* xref:cops_rspec.adoc#rspecexamplelength[RSpec/ExampleLength] -* xref:cops_rspec.adoc#rspecexamplewithoutdescription[RSpec/ExampleWithoutDescription] -* xref:cops_rspec.adoc#rspecexamplewording[RSpec/ExampleWording] -* xref:cops_rspec.adoc#rspecexcessivedocstringspacing[RSpec/ExcessiveDocstringSpacing] -* xref:cops_rspec.adoc#rspecexpectactual[RSpec/ExpectActual] -* xref:cops_rspec.adoc#rspecexpectchange[RSpec/ExpectChange] -* xref:cops_rspec.adoc#rspecexpectinhook[RSpec/ExpectInHook] -* xref:cops_rspec.adoc#rspecexpectoutput[RSpec/ExpectOutput] -* xref:cops_rspec.adoc#rspecfilepath[RSpec/FilePath] -* xref:cops_rspec.adoc#rspecfocus[RSpec/Focus] -* xref:cops_rspec.adoc#rspechookargument[RSpec/HookArgument] -* xref:cops_rspec.adoc#rspechooksbeforeexamples[RSpec/HooksBeforeExamples] -* xref:cops_rspec.adoc#rspecidenticalequalityassertion[RSpec/IdenticalEqualityAssertion] -* xref:cops_rspec.adoc#rspecimplicitblockexpectation[RSpec/ImplicitBlockExpectation] -* xref:cops_rspec.adoc#rspecimplicitexpect[RSpec/ImplicitExpect] -* xref:cops_rspec.adoc#rspecimplicitsubject[RSpec/ImplicitSubject] -* xref:cops_rspec.adoc#rspecindexedlet[RSpec/IndexedLet] -* xref:cops_rspec.adoc#rspecinstancespy[RSpec/InstanceSpy] -* xref:cops_rspec.adoc#rspecinstancevariable[RSpec/InstanceVariable] -* xref:cops_rspec.adoc#rspecisexpectedspecify[RSpec/IsExpectedSpecify] -* xref:cops_rspec.adoc#rspecitbehaveslike[RSpec/ItBehavesLike] -* xref:cops_rspec.adoc#rspeciteratedexpectation[RSpec/IteratedExpectation] -* xref:cops_rspec.adoc#rspecleadingsubject[RSpec/LeadingSubject] -* xref:cops_rspec.adoc#rspecleakyconstantdeclaration[RSpec/LeakyConstantDeclaration] -* xref:cops_rspec.adoc#rspecletbeforeexamples[RSpec/LetBeforeExamples] -* xref:cops_rspec.adoc#rspecletsetup[RSpec/LetSetup] -* xref:cops_rspec.adoc#rspecmatcharray[RSpec/MatchArray] -* xref:cops_rspec.adoc#rspecmessagechain[RSpec/MessageChain] -* xref:cops_rspec.adoc#rspecmessageexpectation[RSpec/MessageExpectation] -* xref:cops_rspec.adoc#rspecmessagespies[RSpec/MessageSpies] -* xref:cops_rspec.adoc#rspecmetadatastyle[RSpec/MetadataStyle] -* xref:cops_rspec.adoc#rspecmissingexamplegroupargument[RSpec/MissingExampleGroupArgument] -* xref:cops_rspec.adoc#rspecmultipledescribes[RSpec/MultipleDescribes] -* xref:cops_rspec.adoc#rspecmultipleexpectations[RSpec/MultipleExpectations] -* xref:cops_rspec.adoc#rspecmultiplememoizedhelpers[RSpec/MultipleMemoizedHelpers] -* xref:cops_rspec.adoc#rspecmultiplesubjects[RSpec/MultipleSubjects] -* xref:cops_rspec.adoc#rspecnamedsubject[RSpec/NamedSubject] -* xref:cops_rspec.adoc#rspecnestedgroups[RSpec/NestedGroups] -* xref:cops_rspec.adoc#rspecnoexpectationexample[RSpec/NoExpectationExample] -* xref:cops_rspec.adoc#rspecnottonot[RSpec/NotToNot] -* xref:cops_rspec.adoc#rspecoverwritingsetup[RSpec/OverwritingSetup] -* xref:cops_rspec.adoc#rspecpending[RSpec/Pending] -* xref:cops_rspec.adoc#rspecpendingwithoutreason[RSpec/PendingWithoutReason] -* xref:cops_rspec.adoc#rspecpredicatematcher[RSpec/PredicateMatcher] -* xref:cops_rspec.adoc#rspecreceivecounts[RSpec/ReceiveCounts] -* xref:cops_rspec.adoc#rspecreceivemessages[RSpec/ReceiveMessages] -* xref:cops_rspec.adoc#rspecreceivenever[RSpec/ReceiveNever] -* xref:cops_rspec.adoc#rspecredundantaround[RSpec/RedundantAround] -* xref:cops_rspec.adoc#rspecredundantpredicatematcher[RSpec/RedundantPredicateMatcher] -* xref:cops_rspec.adoc#rspecremoveconst[RSpec/RemoveConst] -* xref:cops_rspec.adoc#rspecrepeateddescription[RSpec/RepeatedDescription] -* xref:cops_rspec.adoc#rspecrepeatedexample[RSpec/RepeatedExample] -* xref:cops_rspec.adoc#rspecrepeatedexamplegroupbody[RSpec/RepeatedExampleGroupBody] -* xref:cops_rspec.adoc#rspecrepeatedexamplegroupdescription[RSpec/RepeatedExampleGroupDescription] -* xref:cops_rspec.adoc#rspecrepeatedincludeexample[RSpec/RepeatedIncludeExample] -* xref:cops_rspec.adoc#rspecrepeatedsubjectcall[RSpec/RepeatedSubjectCall] -* xref:cops_rspec.adoc#rspecreturnfromstub[RSpec/ReturnFromStub] -* xref:cops_rspec.adoc#rspecscatteredlet[RSpec/ScatteredLet] -* xref:cops_rspec.adoc#rspecscatteredsetup[RSpec/ScatteredSetup] -* xref:cops_rspec.adoc#rspecsharedcontext[RSpec/SharedContext] -* xref:cops_rspec.adoc#rspecsharedexamples[RSpec/SharedExamples] -* xref:cops_rspec.adoc#rspecsingleargumentmessagechain[RSpec/SingleArgumentMessageChain] -* xref:cops_rspec.adoc#rspecskipblockinsideexample[RSpec/SkipBlockInsideExample] -* xref:cops_rspec.adoc#rspecsortmetadata[RSpec/SortMetadata] -* xref:cops_rspec.adoc#rspecspecfilepathformat[RSpec/SpecFilePathFormat] -* xref:cops_rspec.adoc#rspecspecfilepathsuffix[RSpec/SpecFilePathSuffix] -* xref:cops_rspec.adoc#rspecstubbedmock[RSpec/StubbedMock] -* xref:cops_rspec.adoc#rspecsubjectdeclaration[RSpec/SubjectDeclaration] -* xref:cops_rspec.adoc#rspecsubjectstub[RSpec/SubjectStub] -* xref:cops_rspec.adoc#rspecunspecifiedexception[RSpec/UnspecifiedException] -* xref:cops_rspec.adoc#rspecvariabledefinition[RSpec/VariableDefinition] -* xref:cops_rspec.adoc#rspecvariablename[RSpec/VariableName] -* xref:cops_rspec.adoc#rspecverifieddoublereference[RSpec/VerifiedDoubleReference] -* xref:cops_rspec.adoc#rspecverifieddoubles[RSpec/VerifiedDoubles] -* xref:cops_rspec.adoc#rspecvoidexpect[RSpec/VoidExpect] -* xref:cops_rspec.adoc#rspecyield[RSpec/Yield] - -=== Department xref:cops_rspec_capybara.adoc[RSpec/Capybara] - -* xref:cops_rspec_capybara.adoc#rspeccapybara/currentpathexpectation[RSpec/Capybara/CurrentPathExpectation] -* xref:cops_rspec_capybara.adoc#rspeccapybara/featuremethods[RSpec/Capybara/FeatureMethods] -* xref:cops_rspec_capybara.adoc#rspeccapybara/matchstyle[RSpec/Capybara/MatchStyle] -* xref:cops_rspec_capybara.adoc#rspeccapybara/negationmatcher[RSpec/Capybara/NegationMatcher] -* xref:cops_rspec_capybara.adoc#rspeccapybara/specificactions[RSpec/Capybara/SpecificActions] -* xref:cops_rspec_capybara.adoc#rspeccapybara/specificfinders[RSpec/Capybara/SpecificFinders] -* xref:cops_rspec_capybara.adoc#rspeccapybara/specificmatcher[RSpec/Capybara/SpecificMatcher] -* xref:cops_rspec_capybara.adoc#rspeccapybara/visibilitymatcher[RSpec/Capybara/VisibilityMatcher] - -=== Department xref:cops_rspec_factorybot.adoc[RSpec/FactoryBot] - -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/attributedefinedstatically[RSpec/FactoryBot/AttributeDefinedStatically] -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/consistentparenthesesstyle[RSpec/FactoryBot/ConsistentParenthesesStyle] -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/createlist[RSpec/FactoryBot/CreateList] -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/factoryclassname[RSpec/FactoryBot/FactoryClassName] -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/factorynamestyle[RSpec/FactoryBot/FactoryNameStyle] -* xref:cops_rspec_factorybot.adoc#rspecfactorybot/syntaxmethods[RSpec/FactoryBot/SyntaxMethods] - -=== Department xref:cops_rspec_rails.adoc[RSpec/Rails] - -* xref:cops_rspec_rails.adoc#rspecrails/avoidsetuphook[RSpec/Rails/AvoidSetupHook] -* xref:cops_rspec_rails.adoc#rspecrails/havehttpstatus[RSpec/Rails/HaveHttpStatus] -* xref:cops_rspec_rails.adoc#rspecrails/httpstatus[RSpec/Rails/HttpStatus] -* xref:cops_rspec_rails.adoc#rspecrails/inferredspectype[RSpec/Rails/InferredSpecType] -* xref:cops_rspec_rails.adoc#rspecrails/minitestassertions[RSpec/Rails/MinitestAssertions] -* xref:cops_rspec_rails.adoc#rspecrails/negationbevalid[RSpec/Rails/NegationBeValid] -* xref:cops_rspec_rails.adoc#rspecrails/travelaround[RSpec/Rails/TravelAround] +=== Department xref:cops_rspecrails.adoc[RSpecRails] + +* xref:cops_rspecrails.adoc#rspecrailsavoidsetuphook[RSpecRails/AvoidSetupHook] +* xref:cops_rspecrails.adoc#rspecrailshavehttpstatus[RSpecRails/HaveHttpStatus] +* xref:cops_rspecrails.adoc#rspecrailshttpstatus[RSpecRails/HttpStatus] +* xref:cops_rspecrails.adoc#rspecrailsinferredspectype[RSpecRails/InferredSpecType] +* xref:cops_rspecrails.adoc#rspecrailsminitestassertions[RSpecRails/MinitestAssertions] +* xref:cops_rspecrails.adoc#rspecrailsnegationbevalid[RSpecRails/NegationBeValid] +* xref:cops_rspecrails.adoc#rspecrailstravelaround[RSpecRails/TravelAround] // END_COP_LIST diff --git a/docs/modules/ROOT/pages/cops_rspecrails.adoc b/docs/modules/ROOT/pages/cops_rspecrails.adoc index b956d299..e96db232 100644 --- a/docs/modules/ROOT/pages/cops_rspecrails.adoc +++ b/docs/modules/ROOT/pages/cops_rspecrails.adoc @@ -4,9 +4,9 @@ Please make any necessary changes to the cop documentation within the source files themselves. //// -= RSpec/Rails += RSpecRails -== RSpec/Rails/AvoidSetupHook +== RSpecRails/AvoidSetupHook |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -37,9 +37,9 @@ end === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/AvoidSetupHook -== RSpec/Rails/HaveHttpStatus +== RSpecRails/HaveHttpStatus |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -95,9 +95,9 @@ expect(last_response).to have_http_status(200) === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HaveHttpStatus +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HaveHttpStatus -== RSpec/Rails/HttpStatus +== RSpecRails/HttpStatus |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -183,9 +183,9 @@ it { is_expected.to have_http_status :error } === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatus -== RSpec/Rails/InferredSpecType +== RSpecRails/InferredSpecType |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -234,7 +234,7 @@ end [source,ruby] ---- # .rubocop.yml -# RSpec/Rails/InferredSpecType: +# RSpecRails/InferredSpecType: # Inferences: # services: service @@ -266,9 +266,9 @@ end === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/InferredSpecType +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/InferredSpecType -== RSpec/Rails/MinitestAssertions +== RSpecRails/MinitestAssertions |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -312,9 +312,9 @@ expect(a).to be(false) === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/MinitestAssertions +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/MinitestAssertions -== RSpec/Rails/NegationBeValid +== RSpecRails/NegationBeValid |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -375,9 +375,9 @@ expect(foo).to be_invalid.or be_even === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/NegationBeValid -== RSpec/Rails/TravelAround +== RSpecRails/TravelAround |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -417,4 +417,4 @@ before { freeze_time } === References -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/TravelAround +* https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/TravelAround diff --git a/docs/modules/ROOT/pages/development.adoc b/docs/modules/ROOT/pages/development.adoc index f10522d0..c0a7f710 100644 --- a/docs/modules/ROOT/pages/development.adoc +++ b/docs/modules/ROOT/pages/development.adoc @@ -1,32 +1,3 @@ = Development -This page describes considerations when developing RSpec-specific cops. It is intended to be a complement to the general https://docs.rubocop.org/rubocop/development.html[RuboCop development documentation]. - -== Base class - -The `RuboCop::Cop::RSpec::Base` class includes convenient https://docs.rubocop.org/rubocop-ast/node_pattern.html[node pattern DSL] matchers that will automatically account for any xref:usage.adoc#rspec-dsl-configuration[custom RSpec DSL configuration]. - -For example, if the project defines https://github.com/test-prof/test-prof/blob/master/docs/recipes/let_it_be.md[`let_it_be`] as a `Helper`, then all cops will find `let_it_be` when using the `let?` matcher. - -== Writing specs - -When working on RSpec-specific cops, ensure that the https://github.com/rubocop/rubocop-rspec/blob/master/config/default.yml[default language config] is loaded for all RSpec specs. For example: - -[source,ruby] ----- -require 'rubocop/rspec/shared_contexts/default_rspec_language_config_context' - -RSpec.config do |config| - # Set metadata on all cop specs - config.define_derived_metadata(file_path: %r{/spec/rubocop/cop/}) do |meta| - meta[:type] = :cop_spec - end - - # Include RuboCop's config shared context for all cop specs - config.define_derived_metadata(type: :cop_spec) do |meta| - meta[:config] = true - end - - config.include_context 'with default RSpec/Language config', :config -end ----- +This page describes considerations when developing RSpec Rails-specific cops. It is intended to be a complement to the general https://docs.rubocop.org/rubocop/development.html[RuboCop development documentation]. diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index e6a27ef5..cc43cc03 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -1,9 +1,9 @@ -= RuboCop RSpec += RuboCop RSpec Rails -https://rspec.info/[RSpec]-specific analysis for your projects, as an extension to +https://rspec.info/features/6-1/rspec-rails/[RSpec Rails]-specific analysis for your projects, as an extension to https://github.com/rubocop/rubocop[RuboCop]. -RuboCop RSpec follows the https://docs.rubocop.org/rubocop/versioning.html[RuboCop versioning guide]. +RuboCop RSpec Rails follows the https://docs.rubocop.org/rubocop/versioning.html[RuboCop versioning guide]. In a nutshell, between major versions new cops are introduced in a special `pending` status. That means that they won't be run unless explicitly told otherwise. RuboCop will warn on start that certain cops are neither explicitly enabled and disabled. @@ -11,49 +11,4 @@ On a major version release, all `pending` cops are enabled. == Project Goals -* Enforce the guidelines and best practices outlined in the community https://rspec.rubystyle.guide[RSpec style guide] -* Simplify the process of adopting new RSpec functionality - -== Non-goals of RuboCop RSpec - -=== Enforcing `should` vs. `expect` syntax - -Enforcing - -[source,ruby] ----- -expect(calculator.compute(line_item)).to eq(5) ----- - -over - -[source,ruby] ----- -calculator.compute(line_item).should == 5 ----- - -is a feature of RSpec itself - you can read about it in the "Disable should syntax" section of https://rspec.info/features/3-12/rspec-expectations/syntax-configuration[RSpec Documentation]. - -=== Enforcing an explicit RSpec receiver for top-level methods (disabling monkey patching) - -Enforcing - -[source,ruby] ----- -RSpec.describe MyClass do - ... -end ----- - -over - -[source,ruby] ----- -describe MyClass do - ... -end ----- - -can be achieved using RSpec's `disable_monkey_patching!` method, which you can read more about in the https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode[RSpec Documentation]. This will also prevent `should` from being defined on every object in your system. - -Before disabling `should` you will need all your specs to use the `expect` syntax. You can use http://yujinakayama.me/transpec/[Transpec], which will do the conversion for you. +* Simplify the process of adopting new RSpec Rails functionality diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index dda8f545..9ef3d5af 100644 --- a/docs/modules/ROOT/pages/installation.adoc +++ b/docs/modules/ROOT/pages/installation.adoc @@ -1,15 +1,15 @@ = Installation -Just install the `rubocop-rspec` gem +Just install the `rubocop-rspec_rails` gem [source,bash] ---- -gem install rubocop-rspec +gem install rubocop-rspec_rails ---- or if you use bundler put this in your `Gemfile` [source,ruby] ---- -gem 'rubocop-rspec' +gem 'rubocop-rspec_rails' ---- diff --git a/docs/modules/ROOT/pages/usage.adoc b/docs/modules/ROOT/pages/usage.adoc index dd381a68..26f08c2e 100644 --- a/docs/modules/ROOT/pages/usage.adoc +++ b/docs/modules/ROOT/pages/usage.adoc @@ -1,6 +1,6 @@ = Usage -You need to tell RuboCop to load the RSpec extension. +You need to tell RuboCop to load the RSpec Rails extension. There are three ways to do this: == RuboCop configuration file @@ -8,7 +8,7 @@ There are three ways to do this: Put this into your `.rubocop.yml`: ---- -require: rubocop-rspec +require: rubocop-rspec_rails ---- or, if you are using several extensions: @@ -16,69 +16,17 @@ or, if you are using several extensions: ---- require: - rubocop-rspec - - rubocop-performance + - rubocop-rspec_rails ---- -Now you can run `rubocop` and it will automatically load the RuboCop RSpec +Now you can run `rubocop` and it will automatically load the RuboCop RSpec Rails cops together with the standard cops. -=== RSpec DSL configuration - -In case you https://github.com/rspec/rspec-core/blob/b0d0843a285693c64cdbe0c85726db155b46047e/lib/rspec/core/configuration.rb#L1122[define aliases for RSpec DSL], i.e. examples, example groups, hooks, or include example statements, you need to configure it so those elements are properly detected by RuboCop RSpec. - -[source,ruby] ----- -# spec/spec_helper.rb -RSpec.configure do |c| - c.alias_example_group_to :detail, :detailed => true -end - -# spec/detail_spec.rb -RSpec.detail "a detail" do - it "can do some less important stuff" do - end -end ----- - -[source,yaml] ----- -# .rubocop.yml -RSpec: - Language: - ExampleGroups: - Regular: - - detail ----- - -Some libraries extensively define RSpec DSL aliases (e.g. Pundit, Action Policy) or augment existing elements providing the same semantics (e.g. `let_it_be` from `test-prof`). -Those libraries can provide necessary configuration, but won't necessarily do so. -If they do, their README will mention that you have to explicitly require their configuration from your `.rubocop.yml` file. - -[source,yaml] ----- -# .rubocop.yml - -require: - - rubocop-rspec - - test-prof - -# or - -RSpec: - Language: - Helpers: - - let_it_be ----- - -NOTE: the default merge mode is to inherit, so you won't remove any of the default settings. - -RuboCop RSpec's https://github.com/rubocop/rubocop-rspec/blob/a43424527c09fae2e6ddb133f4b2988f6c46bb2e/config/default.yml#L6[default configuration] is a good source of information on what can be configured. - == Command line [source,bash] ---- -$ rubocop --require rubocop-rspec +$ rubocop --require rubocop-rspec_rails ---- == Rake task @@ -86,22 +34,18 @@ $ rubocop --require rubocop-rspec [source,ruby] ---- RuboCop::RakeTask.new do |task| - task.requires << 'rubocop-rspec' + task.requires << 'rubocop-rspec_rails' end ---- -== Code Climate - -`rubocop-rspec` is available on Code Climate as part of the rubocop engine. https://codeclimate.com/changelog/55a433bbe30ba00852000fac[Learn More]. - == Inspecting files that don't end with `_spec.rb` -By default, `rubocop-rspec` only inspects code within paths ending in `_spec.rb` or including `spec/`. You can override this setting in your config file by setting `Include`: +By default, `rubocop-rspec_rails` only inspects code within paths ending in `_spec.rb` or including `spec/`. You can override this setting in your config file by setting `Include`: [source,yaml] ---- # Inspect files in `test/` directory -RSpec: +RSpecRails: Include: - '**/test/**/*' ---- @@ -109,7 +53,7 @@ RSpec: [source,yaml] ---- # Inspect only files ending with `_test.rb` -RSpec: +RSpecRails: Include: - '**/*_test.rb' ---- diff --git a/lib/rubocop-rspec_rails.rb b/lib/rubocop-rspec_rails.rb index 21a2d1f9..c0ecf79f 100644 --- a/lib/rubocop-rspec_rails.rb +++ b/lib/rubocop-rspec_rails.rb @@ -4,63 +4,11 @@ require 'yaml' require 'rubocop' -require 'rubocop-capybara' -require 'rubocop-factory_bot' +require 'rubocop-rspec' -require_relative 'rubocop/rspec' -require_relative 'rubocop/rspec/inject' -require_relative 'rubocop/rspec/language/node_pattern' -require_relative 'rubocop/rspec/node' -require_relative 'rubocop/rspec/version' -require_relative 'rubocop/rspec/wording' +require_relative 'rubocop/rspec_rails/version' -# Dependent on `RuboCop::RSpec::Language::NodePattern`. -require_relative 'rubocop/rspec/language' +require_relative 'rubocop/cop/rspec_rails_cops' -require_relative 'rubocop/cop/rspec/mixin/file_help' -require_relative 'rubocop/cop/rspec/mixin/final_end_location' -require_relative 'rubocop/cop/rspec/mixin/inside_example_group' -require_relative 'rubocop/cop/rspec/mixin/location_help' -require_relative 'rubocop/cop/rspec/mixin/metadata' -require_relative 'rubocop/cop/rspec/mixin/namespace' -require_relative 'rubocop/cop/rspec/mixin/skip_or_pending' -require_relative 'rubocop/cop/rspec/mixin/top_level_group' -require_relative 'rubocop/cop/rspec/mixin/variable' - -# Dependent on `RuboCop::Cop::RSpec::FinalEndLocation`. -require_relative 'rubocop/cop/rspec/mixin/comments_help' -require_relative 'rubocop/cop/rspec/mixin/empty_line_separation' - -require_relative 'rubocop/cop/rspec/base' -require_relative 'rubocop/rspec/align_let_brace' -require_relative 'rubocop/rspec/concept' -require_relative 'rubocop/rspec/corrector/move_node' -require_relative 'rubocop/rspec/example' -require_relative 'rubocop/rspec/example_group' -require_relative 'rubocop/rspec/hook' - -RuboCop::RSpec::Inject.defaults! - -require_relative 'rubocop/cop/rspec_cops' - -# We have to register our autocorrect incompatibilities in RuboCop's cops -# as well so we do not hit infinite loops - -RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend( - Module.new do - def autocorrect_incompatible_with - super.push(RuboCop::Cop::RSpec::AlignLeftLetBrace) - .push(RuboCop::Cop::RSpec::AlignRightLetBrace) - end - end -) - -RuboCop::Cop::Style::TrailingCommaInArguments.singleton_class.prepend( - Module.new do - def autocorrect_incompatible_with - super.push(RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation) - end - end -) - -RuboCop::AST::Node.include(RuboCop::RSpec::Node) +project_root = File.join(__dir__, '..') +RuboCop::ConfigLoader.inject_defaults!(project_root) diff --git a/lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb b/lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb index 832df805..9b0b5678 100644 --- a/lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb +++ b/lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb @@ -2,38 +2,36 @@ module RuboCop module Cop - module RSpec - module Rails - # Checks that tests use RSpec `before` hook over Rails `setup` method. - # - # @example - # # bad - # setup do - # allow(foo).to receive(:bar) - # end - # - # # good - # before do - # allow(foo).to receive(:bar) - # end - # - class AvoidSetupHook < Base - extend AutoCorrector + module RSpecRails + # Checks that tests use RSpec `before` hook over Rails `setup` method. + # + # @example + # # bad + # setup do + # allow(foo).to receive(:bar) + # end + # + # # good + # before do + # allow(foo).to receive(:bar) + # end + # + class AvoidSetupHook < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector - MSG = 'Use `before` instead of `setup`.' + MSG = 'Use `before` instead of `setup`.' - # @!method setup_call(node) - def_node_matcher :setup_call, <<~PATTERN - (block - $(send nil? :setup) - (args) _) - PATTERN + # @!method setup_call(node) + def_node_matcher :setup_call, <<~PATTERN + (block + $(send nil? :setup) + (args) _) + PATTERN - def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler - setup_call(node) do |setup| - add_offense(node) do |corrector| - corrector.replace setup, 'before' - end + def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler + setup_call(node) do |setup| + add_offense(node) do |corrector| + corrector.replace setup, 'before' end end end diff --git a/lib/rubocop/cop/rspec_rails/have_http_status.rb b/lib/rubocop/cop/rspec_rails/have_http_status.rb index 678b212b..71bd168d 100644 --- a/lib/rubocop/cop/rspec_rails/have_http_status.rb +++ b/lib/rubocop/cop/rspec_rails/have_http_status.rb @@ -2,76 +2,74 @@ module RuboCop module Cop - module RSpec - module Rails - # Checks that tests use `have_http_status` instead of equality matchers. - # - # @example ResponseMethods: ['response', 'last_response'] (default) - # # bad - # expect(response.status).to be(200) - # expect(last_response.code).to eq("200") - # - # # good - # expect(response).to have_http_status(200) - # expect(last_response).to have_http_status(200) - # - # @example ResponseMethods: ['foo_response'] - # # bad - # expect(foo_response.status).to be(200) - # - # # good - # expect(foo_response).to have_http_status(200) - # - # # also good - # expect(response).to have_http_status(200) - # expect(last_response).to have_http_status(200) - # - class HaveHttpStatus < ::RuboCop::Cop::Base - extend AutoCorrector + module RSpecRails + # Checks that tests use `have_http_status` instead of equality matchers. + # + # @example ResponseMethods: ['response', 'last_response'] (default) + # # bad + # expect(response.status).to be(200) + # expect(last_response.code).to eq("200") + # + # # good + # expect(response).to have_http_status(200) + # expect(last_response).to have_http_status(200) + # + # @example ResponseMethods: ['foo_response'] + # # bad + # expect(foo_response.status).to be(200) + # + # # good + # expect(foo_response).to have_http_status(200) + # + # # also good + # expect(response).to have_http_status(200) + # expect(last_response).to have_http_status(200) + # + class HaveHttpStatus < ::RuboCop::Cop::Base + extend AutoCorrector - MSG = - 'Prefer `expect(%s).%s ' \ - 'have_http_status(%s)` over `%s`.' + MSG = + 'Prefer `expect(%s).%s ' \ + 'have_http_status(%s)` over `%s`.' - RUNNERS = %i[to to_not not_to].to_set - RESTRICT_ON_SEND = RUNNERS + RUNNERS = %i[to to_not not_to].to_set + RESTRICT_ON_SEND = RUNNERS - # @!method match_status(node) - def_node_matcher :match_status, <<~PATTERN - (send - (send nil? :expect - $(send $(send nil? #response_methods?) {:status :code}) - ) - $RUNNERS - $(send nil? {:be :eq :eql :equal} ({int str} $_)) + # @!method match_status(node) + def_node_matcher :match_status, <<~PATTERN + (send + (send nil? :expect + $(send $(send nil? #response_methods?) {:status :code}) ) - PATTERN + $RUNNERS + $(send nil? {:be :eq :eql :equal} ({int str} $_)) + ) + PATTERN - def on_send(node) # rubocop:disable Metrics/MethodLength - match_status(node) do - |response_status, response_method, to, match, status| - return unless status.to_s.match?(/\A\d+\z/) + def on_send(node) # rubocop:disable Metrics/MethodLength + match_status(node) do + |response_status, response_method, to, match, status| + return unless status.to_s.match?(/\A\d+\z/) - message = format(MSG, response: response_method.method_name, - to: to, status: status, - bad_code: node.source) - add_offense(node, message: message) do |corrector| - corrector.replace(response_status, response_method.method_name) - corrector.replace(match.loc.selector, 'have_http_status') - corrector.replace(match.first_argument, status.to_s) - end + message = format(MSG, response: response_method.method_name, + to: to, status: status, + bad_code: node.source) + add_offense(node, message: message) do |corrector| + corrector.replace(response_status, response_method.method_name) + corrector.replace(match.loc.selector, 'have_http_status') + corrector.replace(match.first_argument, status.to_s) end end + end - private + private - def response_methods?(name) - response_methods.include?(name.to_s) - end + def response_methods?(name) + response_methods.include?(name.to_s) + end - def response_methods - cop_config.fetch('ResponseMethods', []) - end + def response_methods + cop_config.fetch('ResponseMethods', []) end end end diff --git a/lib/rubocop/cop/rspec_rails/http_status.rb b/lib/rubocop/cop/rspec_rails/http_status.rb index d99e1e40..0311b96d 100644 --- a/lib/rubocop/cop/rspec_rails/http_status.rb +++ b/lib/rubocop/cop/rspec_rails/http_status.rb @@ -4,207 +4,205 @@ module RuboCop module Cop - module RSpec - module Rails - # Enforces use of symbolic or numeric value to describe HTTP status. - # - # This cop inspects only `have_http_status` calls. - # So, this cop does not check if a method starting with `be_*` is used - # when setting for `EnforcedStyle: symbolic` or - # `EnforcedStyle: numeric`. - # - # @example `EnforcedStyle: symbolic` (default) - # # bad - # it { is_expected.to have_http_status 200 } - # it { is_expected.to have_http_status 404 } - # it { is_expected.to have_http_status "403" } - # - # # good - # it { is_expected.to have_http_status :ok } - # it { is_expected.to have_http_status :not_found } - # it { is_expected.to have_http_status :forbidden } - # it { is_expected.to have_http_status :success } - # it { is_expected.to have_http_status :error } - # - # @example `EnforcedStyle: numeric` - # # bad - # it { is_expected.to have_http_status :ok } - # it { is_expected.to have_http_status :not_found } - # it { is_expected.to have_http_status "forbidden" } - # - # # good - # it { is_expected.to have_http_status 200 } - # it { is_expected.to have_http_status 404 } - # it { is_expected.to have_http_status 403 } - # it { is_expected.to have_http_status :success } - # it { is_expected.to have_http_status :error } - # - # @example `EnforcedStyle: be_status` - # # bad - # it { is_expected.to have_http_status :ok } - # it { is_expected.to have_http_status :not_found } - # it { is_expected.to have_http_status "forbidden" } - # it { is_expected.to have_http_status 200 } - # it { is_expected.to have_http_status 404 } - # it { is_expected.to have_http_status "403" } - # - # # good - # it { is_expected.to be_ok } - # it { is_expected.to be_not_found } - # it { is_expected.to have_http_status :success } - # it { is_expected.to have_http_status :error } - # - class HttpStatus < Base - extend AutoCorrector - include ConfigurableEnforcedStyle - RESTRICT_ON_SEND = %i[have_http_status].freeze - - # @!method http_status(node) - def_node_matcher :http_status, <<~PATTERN - (send nil? :have_http_status ${int sym str}) - PATTERN - - def on_send(node) - http_status(node) do |arg| - return if arg.str_type? && arg.heredoc? - - checker = checker_class.new(arg) - return unless checker.offensive? - - add_offense(checker.offense_range, - message: checker.message) do |corrector| - corrector.replace(checker.offense_range, checker.prefer) - end + module RSpecRails + # Enforces use of symbolic or numeric value to describe HTTP status. + # + # This cop inspects only `have_http_status` calls. + # So, this cop does not check if a method starting with `be_*` is used + # when setting for `EnforcedStyle: symbolic` or + # `EnforcedStyle: numeric`. + # + # @example `EnforcedStyle: symbolic` (default) + # # bad + # it { is_expected.to have_http_status 200 } + # it { is_expected.to have_http_status 404 } + # it { is_expected.to have_http_status "403" } + # + # # good + # it { is_expected.to have_http_status :ok } + # it { is_expected.to have_http_status :not_found } + # it { is_expected.to have_http_status :forbidden } + # it { is_expected.to have_http_status :success } + # it { is_expected.to have_http_status :error } + # + # @example `EnforcedStyle: numeric` + # # bad + # it { is_expected.to have_http_status :ok } + # it { is_expected.to have_http_status :not_found } + # it { is_expected.to have_http_status "forbidden" } + # + # # good + # it { is_expected.to have_http_status 200 } + # it { is_expected.to have_http_status 404 } + # it { is_expected.to have_http_status 403 } + # it { is_expected.to have_http_status :success } + # it { is_expected.to have_http_status :error } + # + # @example `EnforcedStyle: be_status` + # # bad + # it { is_expected.to have_http_status :ok } + # it { is_expected.to have_http_status :not_found } + # it { is_expected.to have_http_status "forbidden" } + # it { is_expected.to have_http_status 200 } + # it { is_expected.to have_http_status 404 } + # it { is_expected.to have_http_status "403" } + # + # # good + # it { is_expected.to be_ok } + # it { is_expected.to be_not_found } + # it { is_expected.to have_http_status :success } + # it { is_expected.to have_http_status :error } + # + class HttpStatus < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector + include ConfigurableEnforcedStyle + RESTRICT_ON_SEND = %i[have_http_status].freeze + + # @!method http_status(node) + def_node_matcher :http_status, <<~PATTERN + (send nil? :have_http_status ${int sym str}) + PATTERN + + def on_send(node) + http_status(node) do |arg| + return if arg.str_type? && arg.heredoc? + + checker = checker_class.new(arg) + return unless checker.offensive? + + add_offense(checker.offense_range, + message: checker.message) do |corrector| + corrector.replace(checker.offense_range, checker.prefer) end end + end - private + private - def checker_class - case style - when :symbolic - SymbolicStyleChecker - when :numeric - NumericStyleChecker - when :be_status - BeStatusStyleChecker - end + def checker_class + case style + when :symbolic + SymbolicStyleChecker + when :numeric + NumericStyleChecker + when :be_status + BeStatusStyleChecker end + end - # :nodoc: - class StyleCheckerBase - MSG = 'Prefer `%s` over `%s` ' \ - 'to describe HTTP status code.' - ALLOWED_STATUSES = %i[error success missing redirect].freeze + # :nodoc: + class StyleCheckerBase + MSG = 'Prefer `%s` over `%s` ' \ + 'to describe HTTP status code.' + ALLOWED_STATUSES = %i[error success missing redirect].freeze - attr_reader :node + attr_reader :node - def initialize(node) - @node = node - end + def initialize(node) + @node = node + end - def message - format(MSG, prefer: prefer, current: current) - end + def message + format(MSG, prefer: prefer, current: current) + end - def current - offense_range.source - end + def current + offense_range.source + end - def offense_range - node - end + def offense_range + node + end - def allowed_symbol? - node.sym_type? && ALLOWED_STATUSES.include?(node.value) - end + def allowed_symbol? + node.sym_type? && ALLOWED_STATUSES.include?(node.value) + end - def custom_http_status_code? - node.int_type? && - !::Rack::Utils::SYMBOL_TO_STATUS_CODE.value?(node.source.to_i) - end + def custom_http_status_code? + node.int_type? && + !::Rack::Utils::SYMBOL_TO_STATUS_CODE.value?(node.source.to_i) end + end - # :nodoc: - class SymbolicStyleChecker < StyleCheckerBase - def offensive? - !node.sym_type? && !custom_http_status_code? - end + # :nodoc: + class SymbolicStyleChecker < StyleCheckerBase + def offensive? + !node.sym_type? && !custom_http_status_code? + end - def prefer - symbol.inspect - end + def prefer + symbol.inspect + end - private + private - def symbol - ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(number) - end + def symbol + ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(number) + end - def number - node.value.to_i - end + def number + node.value.to_i end + end - # :nodoc: - class NumericStyleChecker < StyleCheckerBase - def offensive? - !node.int_type? && !allowed_symbol? - end + # :nodoc: + class NumericStyleChecker < StyleCheckerBase + def offensive? + !node.int_type? && !allowed_symbol? + end - def prefer - number.to_s - end + def prefer + number.to_s + end - private + private - def symbol - node.value - end + def symbol + node.value + end - def number - ::Rack::Utils::SYMBOL_TO_STATUS_CODE[symbol.to_sym] - end + def number + ::Rack::Utils::SYMBOL_TO_STATUS_CODE[symbol.to_sym] end + end - # :nodoc: - class BeStatusStyleChecker < StyleCheckerBase - def offensive? - (!node.sym_type? && !custom_http_status_code?) || - (!node.int_type? && !allowed_symbol?) - end + # :nodoc: + class BeStatusStyleChecker < StyleCheckerBase + def offensive? + (!node.sym_type? && !custom_http_status_code?) || + (!node.int_type? && !allowed_symbol?) + end - def offense_range - node.parent - end + def offense_range + node.parent + end - def prefer - if node.sym_type? - "be_#{node.value}" - elsif node.int_type? - "be_#{symbol}" - elsif node.str_type? - "be_#{normalize_str}" - end + def prefer + if node.sym_type? + "be_#{node.value}" + elsif node.int_type? + "be_#{symbol}" + elsif node.str_type? + "be_#{normalize_str}" end + end - private + private - def symbol - ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(number) - end + def symbol + ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(number) + end - def number - node.value.to_i - end + def number + node.value.to_i + end - def normalize_str - str = node.value.to_s - if str.match?(/\A\d+\z/) - ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(str.to_i) - else - str - end + def normalize_str + str = node.value.to_s + if str.match?(/\A\d+\z/) + ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(str.to_i) + else + str end end end diff --git a/lib/rubocop/cop/rspec_rails/inferred_spec_type.rb b/lib/rubocop/cop/rspec_rails/inferred_spec_type.rb index b253a40e..6eff7f08 100644 --- a/lib/rubocop/cop/rspec_rails/inferred_spec_type.rb +++ b/lib/rubocop/cop/rspec_rails/inferred_spec_type.rb @@ -2,142 +2,140 @@ module RuboCop module Cop - module RSpec - module Rails - # Identifies redundant spec type. - # - # After setting up rspec-rails, you will have enabled - # `config.infer_spec_type_from_file_location!` by default in - # spec/rails_helper.rb. This cop works in conjunction with this config. - # If you disable this config, disable this cop as well. - # - # @safety - # This cop is marked as unsafe because - # `config.infer_spec_type_from_file_location!` may not be enabled. - # - # @example - # # bad - # # spec/models/user_spec.rb - # RSpec.describe User, type: :model do - # end - # - # # good - # # spec/models/user_spec.rb - # RSpec.describe User do - # end - # - # # good - # # spec/models/user_spec.rb - # RSpec.describe User, type: :common do - # end - # - # @example `Inferences` configuration - # # .rubocop.yml - # # RSpec/Rails/InferredSpecType: - # # Inferences: - # # services: service - # - # # bad - # # spec/services/user_spec.rb - # RSpec.describe User, type: :service do - # end - # - # # good - # # spec/services/user_spec.rb - # RSpec.describe User do - # end - # - # # good - # # spec/services/user_spec.rb - # RSpec.describe User, type: :common do - # end - class InferredSpecType < Base - extend AutoCorrector + module RSpecRails + # Identifies redundant spec type. + # + # After setting up rspec-rails, you will have enabled + # `config.infer_spec_type_from_file_location!` by default in + # spec/rails_helper.rb. This cop works in conjunction with this config. + # If you disable this config, disable this cop as well. + # + # @safety + # This cop is marked as unsafe because + # `config.infer_spec_type_from_file_location!` may not be enabled. + # + # @example + # # bad + # # spec/models/user_spec.rb + # RSpec.describe User, type: :model do + # end + # + # # good + # # spec/models/user_spec.rb + # RSpec.describe User do + # end + # + # # good + # # spec/models/user_spec.rb + # RSpec.describe User, type: :common do + # end + # + # @example `Inferences` configuration + # # .rubocop.yml + # # RSpecRails/InferredSpecType: + # # Inferences: + # # services: service + # + # # bad + # # spec/services/user_spec.rb + # RSpec.describe User, type: :service do + # end + # + # # good + # # spec/services/user_spec.rb + # RSpec.describe User do + # end + # + # # good + # # spec/services/user_spec.rb + # RSpec.describe User, type: :common do + # end + class InferredSpecType < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector - MSG = 'Remove redundant spec type.' + MSG = 'Remove redundant spec type.' - # @param [RuboCop::AST::BlockNode] node - def on_block(node) - return unless example_group?(node) + # @param [RuboCop::AST::BlockNode] node + def on_block(node) + return unless example_group?(node) - pair_node = describe_with_type(node) - return unless pair_node - return unless inferred_type?(pair_node) + pair_node = describe_with_type(node) + return unless pair_node + return unless inferred_type?(pair_node) - removable_node = detect_removable_node(pair_node) - add_offense(removable_node) do |corrector| - autocorrect(corrector, removable_node) - end + removable_node = detect_removable_node(pair_node) + add_offense(removable_node) do |corrector| + autocorrect(corrector, removable_node) end - alias on_numblock on_block + end + alias on_numblock on_block - private + private - # @!method describe_with_type(node) - # @param [RuboCop::AST::BlockNode] node - # @return [RuboCop::AST::PairNode, nil] - def_node_matcher :describe_with_type, <<~PATTERN - (block - (send #rspec? #ExampleGroups.all - ... - (hash <$(pair (sym :type) sym) ...>) - ) + # @!method describe_with_type(node) + # @param [RuboCop::AST::BlockNode] node + # @return [RuboCop::AST::PairNode, nil] + def_node_matcher :describe_with_type, <<~PATTERN + (block + (send #rspec? #ExampleGroups.all ... + (hash <$(pair (sym :type) sym) ...>) ) - PATTERN + ... + ) + PATTERN - # @param [RuboCop::AST::Corrector] corrector - # @param [RuboCop::AST::Node] node - def autocorrect(corrector, node) - corrector.remove(remove_range(node)) - end + # @param [RuboCop::AST::Corrector] corrector + # @param [RuboCop::AST::Node] node + def autocorrect(corrector, node) + corrector.remove(remove_range(node)) + end - # @param [RuboCop::AST::Node] node - # @return [Parser::Source::Range] - def remove_range(node) - if node.left_sibling - node.source_range.with( - begin_pos: node.left_sibling.source_range.end_pos - ) - elsif node.right_sibling - node.source_range.with( - end_pos: node.right_sibling.source_range.begin_pos - ) - end + # @param [RuboCop::AST::Node] node + # @return [Parser::Source::Range] + def remove_range(node) + if node.left_sibling + node.source_range.with( + begin_pos: node.left_sibling.source_range.end_pos + ) + elsif node.right_sibling + node.source_range.with( + end_pos: node.right_sibling.source_range.begin_pos + ) end + end - # @param [RuboCop::AST::PairNode] node - # @return [RuboCop::AST::Node] - def detect_removable_node(node) - if node.parent.pairs.size == 1 - node.parent - else - node - end + # @param [RuboCop::AST::PairNode] node + # @return [RuboCop::AST::Node] + def detect_removable_node(node) + if node.parent.pairs.size == 1 + node.parent + else + node end + end - # @return [String] - def file_path - processed_source.file_path - end + # @return [String] + def file_path + processed_source.file_path + end - # @param [RuboCop::AST::PairNode] node - # @return [Boolean] - def inferred_type?(node) - inferred_type_from_file_path.inspect == node.value.source - end + # @param [RuboCop::AST::PairNode] node + # @return [Boolean] + def inferred_type?(node) + inferred_type_from_file_path.inspect == node.value.source + end - # @return [Symbol, nil] - def inferred_type_from_file_path - inferences.find do |prefix, type| - break type.to_sym if file_path.include?("spec/#{prefix}/") - end + # @return [Symbol, nil] + def inferred_type_from_file_path + inferences.find do |prefix, type| + break type.to_sym if file_path.include?("spec/#{prefix}/") end + end - # @return [Hash] - def inferences - cop_config['Inferences'] || {} - end + # @return [Hash] + def inferences + cop_config['Inferences'] || {} end end end diff --git a/lib/rubocop/cop/rspec_rails/minitest_assertions.rb b/lib/rubocop/cop/rspec_rails/minitest_assertions.rb index 50c552e9..915244a8 100644 --- a/lib/rubocop/cop/rspec_rails/minitest_assertions.rb +++ b/lib/rubocop/cop/rspec_rails/minitest_assertions.rb @@ -2,361 +2,348 @@ module RuboCop module Cop - module RSpec - module Rails - # Check if using Minitest-like matchers. - # - # Check the use of minitest-like matchers - # starting with `assert_` or `refute_`. - # - # @example - # # bad - # assert_equal(a, b) - # assert_equal a, b, "must be equal" - # assert_not_includes a, b - # refute_equal(a, b) - # assert_nil a - # refute_empty(b) - # assert_true(a) - # assert_false(a) - # - # # good - # expect(b).to eq(a) - # expect(b).to(eq(a), "must be equal") - # expect(a).not_to include(b) - # expect(b).not_to eq(a) - # expect(a).to eq(nil) - # expect(a).not_to be_empty - # expect(a).to be(true) - # expect(a).to be(false) - # - class MinitestAssertions < Base - extend AutoCorrector - - # :nodoc: - class BasicAssertion - extend NodePattern::Macros - - attr_reader :expected, :actual, :failure_message - - def self.minitest_assertion - raise NotImplementedError - end + module RSpecRails + # Check if using Minitest-like matchers. + # + # Check the use of minitest-like matchers + # starting with `assert_` or `refute_`. + # + # @example + # # bad + # assert_equal(a, b) + # assert_equal a, b, "must be equal" + # assert_not_includes a, b + # refute_equal(a, b) + # assert_nil a + # refute_empty(b) + # assert_true(a) + # assert_false(a) + # + # # good + # expect(b).to eq(a) + # expect(b).to(eq(a), "must be equal") + # expect(a).not_to include(b) + # expect(b).not_to eq(a) + # expect(a).to eq(nil) + # expect(a).not_to be_empty + # expect(a).to be(true) + # expect(a).to be(false) + # + class MinitestAssertions < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector + + # :nodoc: + class BasicAssertion + extend NodePattern::Macros + + attr_reader :expected, :actual, :failure_message + + def self.minitest_assertion + raise NotImplementedError + end - def initialize(expected, actual, failure_message) - @expected = expected&.source - @actual = actual.source - @failure_message = failure_message&.source - end + def initialize(expected, actual, failure_message) + @expected = expected&.source + @actual = actual.source + @failure_message = failure_message&.source + end - def replaced(node) - runner = negated?(node) ? 'not_to' : 'to' - if failure_message.nil? - "expect(#{actual}).#{runner} #{assertion}" - else - "expect(#{actual}).#{runner}(#{assertion}, #{failure_message})" - end + def replaced(node) + runner = negated?(node) ? 'not_to' : 'to' + if failure_message.nil? + "expect(#{actual}).#{runner} #{assertion}" + else + "expect(#{actual}).#{runner}(#{assertion}, #{failure_message})" end + end - def negated?(node) - node.method_name.start_with?('assert_not_', 'refute_') - end + def negated?(node) + node.method_name.start_with?('assert_not_', 'refute_') + end - def assertion - raise NotImplementedError - end + def assertion + raise NotImplementedError end + end - # :nodoc: - class EqualAssertion < BasicAssertion - MATCHERS = %i[ - assert_equal - assert_not_equal - refute_equal - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_equal :assert_not_equal :refute_equal} $_ $_ $_?) - PATTERN - - def self.match(expected, actual, failure_message) - new(expected, actual, failure_message.first) - end + # :nodoc: + class EqualAssertion < BasicAssertion + MATCHERS = %i[ + assert_equal + assert_not_equal + refute_equal + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_equal :assert_not_equal :refute_equal} $_ $_ $_?) + PATTERN + + def self.match(expected, actual, failure_message) + new(expected, actual, failure_message.first) + end - def assertion - "eq(#{expected})" - end + def assertion + "eq(#{expected})" end + end - # :nodoc: - class KindOfAssertion < BasicAssertion - MATCHERS = %i[ - assert_kind_of - assert_not_kind_of - refute_kind_of - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_kind_of :assert_not_kind_of :refute_kind_of} $_ $_ $_?) - PATTERN - - def self.match(expected, actual, failure_message) - new(expected, actual, failure_message.first) - end + # :nodoc: + class KindOfAssertion < BasicAssertion + MATCHERS = %i[ + assert_kind_of + assert_not_kind_of + refute_kind_of + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_kind_of :assert_not_kind_of :refute_kind_of} $_ $_ $_?) + PATTERN + + def self.match(expected, actual, failure_message) + new(expected, actual, failure_message.first) + end - def assertion - "be_a_kind_of(#{expected})" - end + def assertion + "be_a_kind_of(#{expected})" end + end - # :nodoc: - class InstanceOfAssertion < BasicAssertion - MATCHERS = %i[ - assert_instance_of - assert_not_instance_of - refute_instance_of - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_instance_of :assert_not_instance_of :refute_instance_of} $_ $_ $_?) - PATTERN - - def self.match(expected, actual, failure_message) - new(expected, actual, failure_message.first) - end + # :nodoc: + class InstanceOfAssertion < BasicAssertion + MATCHERS = %i[ + assert_instance_of + assert_not_instance_of + refute_instance_of + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_instance_of :assert_not_instance_of :refute_instance_of} $_ $_ $_?) + PATTERN + + def self.match(expected, actual, failure_message) + new(expected, actual, failure_message.first) + end - def assertion - "be_an_instance_of(#{expected})" - end + def assertion + "be_an_instance_of(#{expected})" end + end - # :nodoc: - class IncludesAssertion < BasicAssertion - MATCHERS = %i[ - assert_includes - assert_not_includes - refute_includes - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_includes :assert_not_includes :refute_includes} $_ $_ $_?) - PATTERN - - def self.match(collection, expected, failure_message) - new(expected, collection, failure_message.first) - end + # :nodoc: + class IncludesAssertion < BasicAssertion + MATCHERS = %i[ + assert_includes + assert_not_includes + refute_includes + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_includes :assert_not_includes :refute_includes} $_ $_ $_?) + PATTERN + + def self.match(collection, expected, failure_message) + new(expected, collection, failure_message.first) + end - def assertion - "include(#{expected})" - end + def assertion + "include(#{expected})" end + end - # :nodoc: - class InDeltaAssertion < BasicAssertion - MATCHERS = %i[ - assert_in_delta - assert_not_in_delta - refute_in_delta - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $_? $_?) - PATTERN - - def self.match(expected, actual, delta, failure_message) - new(expected, actual, delta.first, failure_message.first) - end + # :nodoc: + class InDeltaAssertion < BasicAssertion + MATCHERS = %i[ + assert_in_delta + assert_not_in_delta + refute_in_delta + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $_? $_?) + PATTERN + + def self.match(expected, actual, delta, failure_message) + new(expected, actual, delta.first, failure_message.first) + end - def initialize(expected, actual, delta, fail_message) - super(expected, actual, fail_message) + def initialize(expected, actual, delta, fail_message) + super(expected, actual, fail_message) - @delta = delta&.source || '0.001' - end + @delta = delta&.source || '0.001' + end - def assertion - "be_within(#{@delta}).of(#{expected})" - end + def assertion + "be_within(#{@delta}).of(#{expected})" end + end - # :nodoc: - class PredicateAssertion < BasicAssertion - MATCHERS = %i[ - assert_predicate - assert_not_predicate - refute_predicate - ].freeze + # :nodoc: + class PredicateAssertion < BasicAssertion + MATCHERS = %i[ + assert_predicate + assert_not_predicate + refute_predicate + ].freeze - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_predicate :assert_not_predicate :refute_predicate} $_ ${sym} $_?) - PATTERN + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_predicate :assert_not_predicate :refute_predicate} $_ ${sym} $_?) + PATTERN - def self.match(subject, predicate, failure_message) - return nil unless predicate.value.end_with?('?') + def self.match(subject, predicate, failure_message) + return nil unless predicate.value.end_with?('?') - new(predicate, subject, failure_message.first) - end + new(predicate, subject, failure_message.first) + end - def assertion - "be_#{expected.delete_prefix(':').delete_suffix('?')}" - end + def assertion + "be_#{expected.delete_prefix(':').delete_suffix('?')}" end + end - # :nodoc: - class MatchAssertion < BasicAssertion - MATCHERS = %i[ - assert_match - refute_match - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_match :refute_match} $_ $_ $_?) - PATTERN - - def self.match(matcher, actual, failure_message) - new(matcher, actual, failure_message.first) - end + # :nodoc: + class MatchAssertion < BasicAssertion + MATCHERS = %i[ + assert_match + refute_match + ].freeze - def assertion - "match(#{expected})" - end + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_match :refute_match} $_ $_ $_?) + PATTERN + + def self.match(matcher, actual, failure_message) + new(matcher, actual, failure_message.first) end - # :nodoc: - class NilAssertion < BasicAssertion - MATCHERS = %i[ - assert_nil - assert_not_nil - refute_nil - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_nil :assert_not_nil :refute_nil} $_ $_?) - PATTERN - - def self.match(actual, failure_message) - new(nil, actual, failure_message.first) - end + def assertion + "match(#{expected})" + end + end - def assertion - 'eq(nil)' - end + # :nodoc: + class NilAssertion < BasicAssertion + MATCHERS = %i[ + assert_nil + assert_not_nil + refute_nil + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_nil :assert_not_nil :refute_nil} $_ $_?) + PATTERN + + def self.match(actual, failure_message) + new(nil, actual, failure_message.first) end - # :nodoc: - class EmptyAssertion < BasicAssertion - MATCHERS = %i[ - assert_empty - assert_not_empty - refute_empty - ].freeze - - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_empty :assert_not_empty :refute_empty} $_ $_?) - PATTERN - - def self.match(actual, failure_message) - new(nil, actual, failure_message.first) - end + def assertion + 'eq(nil)' + end + end - def assertion - 'be_empty' - end + # :nodoc: + class EmptyAssertion < BasicAssertion + MATCHERS = %i[ + assert_empty + assert_not_empty + refute_empty + ].freeze + + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_empty :assert_not_empty :refute_empty} $_ $_?) + PATTERN + + def self.match(actual, failure_message) + new(nil, actual, failure_message.first) end - # :nodoc: - class TrueAssertion < BasicAssertion - MATCHERS = %i[ - assert_true - ].freeze + def assertion + 'be_empty' + end + end - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_true} $_ $_?) - PATTERN + # :nodoc: + class TrueAssertion < BasicAssertion + MATCHERS = %i[ + assert_true + ].freeze - def self.match(actual, failure_message) - new(nil, actual, failure_message.first) - end + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_true} $_ $_?) + PATTERN - def assertion - 'be(true)' - end + def self.match(actual, failure_message) + new(nil, actual, failure_message.first) end - # :nodoc: - class FalseAssertion < BasicAssertion - MATCHERS = %i[ - assert_false - ].freeze + def assertion + 'be(true)' + end + end - # @!method minitest_assertion(node) - # @!scope class - def_node_matcher 'self.minitest_assertion', <<~PATTERN - (send nil? {:assert_false} $_ $_?) - PATTERN + # :nodoc: + class FalseAssertion < BasicAssertion + MATCHERS = %i[ + assert_false + ].freeze - def self.match(actual, failure_message) - new(nil, actual, failure_message.first) - end + # @!method self.minitest_assertion(node) + def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective + (send nil? {:assert_false} $_ $_?) + PATTERN - def assertion - 'be(false)' - end + def self.match(actual, failure_message) + new(nil, actual, failure_message.first) end - MSG = 'Use `%s`.' + def assertion + 'be(false)' + end + end - # TODO: replace with `BasicAssertion.subclasses` in Ruby 3.1+ - ASSERTION_MATCHERS = constants(false).filter_map do |c| - const = const_get(c) + MSG = 'Use `%s`.' - const if const.is_a?(Class) && const.superclass == BasicAssertion - end + # TODO: replace with `BasicAssertion.subclasses` in Ruby 3.1+ + ASSERTION_MATCHERS = constants(false).filter_map do |c| + const = const_get(c) - RESTRICT_ON_SEND = ASSERTION_MATCHERS.flat_map { |m| m::MATCHERS } + const if const.is_a?(Class) && const.superclass == BasicAssertion + end - def on_send(node) - ASSERTION_MATCHERS.each do |m| - m.minitest_assertion(node) do |*args| - assertion = m.match(*args) + RESTRICT_ON_SEND = ASSERTION_MATCHERS.flat_map { |m| m::MATCHERS } - next if assertion.nil? + def on_send(node) + ASSERTION_MATCHERS.each do |m| + m.minitest_assertion(node) do |*args| + assertion = m.match(*args) - on_assertion(node, assertion) - end - end - end + next if assertion.nil? - def on_assertion(node, assertion) - preferred = assertion.replaced(node) - add_offense(node, message: message(preferred)) do |corrector| - corrector.replace(node, preferred) + on_assertion(node, assertion) end end + end - def message(preferred) - format(MSG, prefer: preferred) + def on_assertion(node, assertion) + preferred = assertion.replaced(node) + add_offense(node, message: message(preferred)) do |corrector| + corrector.replace(node, preferred) end end + + def message(preferred) + format(MSG, prefer: preferred) + end end end end diff --git a/lib/rubocop/cop/rspec_rails/negation_be_valid.rb b/lib/rubocop/cop/rspec_rails/negation_be_valid.rb index e2d01358..54f23369 100644 --- a/lib/rubocop/cop/rspec_rails/negation_be_valid.rb +++ b/lib/rubocop/cop/rspec_rails/negation_be_valid.rb @@ -2,98 +2,94 @@ module RuboCop module Cop - module RSpec - module Rails - # Enforces use of `be_invalid` or `not_to` for negated be_valid. - # - # @safety - # This cop is unsafe because it cannot guarantee that - # the test target is an instance of `ActiveModel::Validations``. - # - # @example EnforcedStyle: not_to (default) - # # bad - # expect(foo).to be_invalid - # - # # good - # expect(foo).not_to be_valid - # - # # good (with method chain) - # expect(foo).to be_invalid.and be_odd - # - # @example EnforcedStyle: be_invalid - # # bad - # expect(foo).not_to be_valid - # - # # good - # expect(foo).to be_invalid - # - # # good (with method chain) - # expect(foo).to be_invalid.or be_even - # - class NegationBeValid < Base - extend AutoCorrector - include ConfigurableEnforcedStyle + module RSpecRails + # Enforces use of `be_invalid` or `not_to` for negated be_valid. + # + # @safety + # This cop is unsafe because it cannot guarantee that + # the test target is an instance of `ActiveModel::Validations``. + # + # @example EnforcedStyle: not_to (default) + # # bad + # expect(foo).to be_invalid + # + # # good + # expect(foo).not_to be_valid + # + # # good (with method chain) + # expect(foo).to be_invalid.and be_odd + # + # @example EnforcedStyle: be_invalid + # # bad + # expect(foo).not_to be_valid + # + # # good + # expect(foo).to be_invalid + # + # # good (with method chain) + # expect(foo).to be_invalid.or be_even + # + class NegationBeValid < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector + include ConfigurableEnforcedStyle - MSG = 'Use `expect(...).%s %s`.' - RESTRICT_ON_SEND = %i[be_valid be_invalid].freeze + MSG = 'Use `expect(...).%s %s`.' + RESTRICT_ON_SEND = %i[be_valid be_invalid].freeze - # @!method not_to?(node) - def_node_matcher :not_to?, <<~PATTERN - (send ... :not_to (send nil? :be_valid ...)) - PATTERN + # @!method not_to?(node) + def_node_matcher :not_to?, <<~PATTERN + (send ... :not_to (send nil? :be_valid ...)) + PATTERN - # @!method be_invalid?(node) - def_node_matcher :be_invalid?, <<~PATTERN - (send ... :to (send nil? :be_invalid ...)) - PATTERN + # @!method be_invalid?(node) + def_node_matcher :be_invalid?, <<~PATTERN + (send ... :to (send nil? :be_invalid ...)) + PATTERN - def on_send(node) - return unless offense?(node.parent) + def on_send(node) + return unless offense?(node.parent) - add_offense(offense_range(node), - message: message(node.method_name)) do |corrector| - corrector.replace(node.parent.loc.selector, replaced_runner) - corrector.replace(node.loc.selector, replaced_matcher) - end + add_offense(offense_range(node), + message: message(node.method_name)) do |corrector| + corrector.replace(node.parent.loc.selector, replaced_runner) + corrector.replace(node.loc.selector, replaced_matcher) end + end - private + private - def offense?(node) - case style - when :not_to - be_invalid?(node) - when :be_invalid - not_to?(node) - end + def offense?(node) + case style + when :not_to + be_invalid?(node) + when :be_invalid + not_to?(node) end + end - def offense_range(node) - node.parent.loc.selector.with(end_pos: node.loc.selector.end_pos) - end + def offense_range(node) + node.parent.loc.selector.with(end_pos: node.loc.selector.end_pos) + end - def message(_matcher) - format(MSG, - runner: replaced_runner, - matcher: replaced_matcher) - end + def message(_matcher) + format(MSG, runner: replaced_runner, matcher: replaced_matcher) + end - def replaced_runner - case style - when :not_to - 'not_to' - when :be_invalid - 'to' - end + def replaced_runner + case style + when :not_to + 'not_to' + when :be_invalid + 'to' end + end - def replaced_matcher - case style - when :not_to - 'be_valid' - when :be_invalid - 'be_invalid' - end + def replaced_matcher + case style + when :not_to + 'be_valid' + when :be_invalid + 'be_invalid' end end end diff --git a/lib/rubocop/cop/rspec_rails/travel_around.rb b/lib/rubocop/cop/rspec_rails/travel_around.rb index 175879ca..162a7c8e 100644 --- a/lib/rubocop/cop/rspec_rails/travel_around.rb +++ b/lib/rubocop/cop/rspec_rails/travel_around.rb @@ -2,88 +2,86 @@ module RuboCop module Cop - module RSpec - module Rails - # Prefer to travel in `before` rather than `around`. - # - # @safety - # This cop is unsafe because the automatic `travel_back` is only run - # on test cases that are considered as Rails related. - # - # And also, this cop's autocorrection is unsafe because the order of - # execution will change if other steps exist before traveling in - # `around`. - # - # @example - # # bad - # around do |example| - # freeze_time do - # example.run - # end - # end - # - # # good - # before { freeze_time } - class TravelAround < Base - extend AutoCorrector + module RSpecRails + # Prefer to travel in `before` rather than `around`. + # + # @safety + # This cop is unsafe because the automatic `travel_back` is only run + # on test cases that are considered as Rails related. + # + # And also, this cop's autocorrection is unsafe because the order of + # execution will change if other steps exist before traveling in + # `around`. + # + # @example + # # bad + # around do |example| + # freeze_time do + # example.run + # end + # end + # + # # good + # before { freeze_time } + class TravelAround < ::RuboCop::Cop::RSpec::Base + extend AutoCorrector - MSG = 'Prefer to travel in `before` rather than `around`.' + MSG = 'Prefer to travel in `before` rather than `around`.' - TRAVEL_METHOD_NAMES = %i[ - freeze_time - travel - travel_to - ].to_set.freeze + TRAVEL_METHOD_NAMES = %i[ + freeze_time + travel + travel_to + ].to_set.freeze - # @!method extract_run_in_travel(node) - def_node_matcher :extract_run_in_travel, <<~PATTERN - (block - $(send nil? TRAVEL_METHOD_NAMES ...) - (args ...) - (send _ :run) - ) - PATTERN + # @!method extract_run_in_travel(node) + def_node_matcher :extract_run_in_travel, <<~PATTERN + (block + $(send nil? TRAVEL_METHOD_NAMES ...) + (args ...) + (send _ :run) + ) + PATTERN - # @!method match_around_each?(node) - def_node_matcher :match_around_each?, <<~PATTERN - (block - (send _ :around (sym :each)?) - ... - ) - PATTERN + # @!method match_around_each?(node) + def_node_matcher :match_around_each?, <<~PATTERN + (block + (send _ :around (sym :each)?) + ... + ) + PATTERN - def on_block(node) - run_node = extract_run_in_travel(node) - return unless run_node + def on_block(node) + run_node = extract_run_in_travel(node) + return unless run_node - around_node = extract_surrounding_around_block(run_node) - return unless around_node + around_node = extract_surrounding_around_block(run_node) + return unless around_node - add_offense(node) do |corrector| - autocorrect(corrector, node, run_node, around_node) - end + add_offense(node) do |corrector| + autocorrect(corrector, node, run_node, around_node) end - alias on_numblock on_block + end + alias on_numblock on_block - private + private - def autocorrect(corrector, node, run_node, around_node) - corrector.replace( - node, - node.body.source - ) - corrector.insert_before( - around_node, - "before { #{run_node.source} }\n\n" - ) - end + def autocorrect(corrector, node, run_node, around_node) + corrector.replace( + node, + node.body.source + ) + corrector.insert_before( + around_node, + "before { #{run_node.source} }\n\n" + ) + end - # @param node [RuboCop::AST::BlockNode] - # @return [RuboCop::AST::BlockNode, nil] - def extract_surrounding_around_block(node) - node.each_ancestor(:block).find do |ancestor| - match_around_each?(ancestor) - end + # @param node [RuboCop::AST::BlockNode] + # @return [RuboCop::AST::BlockNode, nil] + def extract_surrounding_around_block(node) + node.each_ancestor(:block).find do |ancestor| + match_around_each?(ancestor) end end end diff --git a/lib/rubocop/cop/rspec_rails_cops.rb b/lib/rubocop/cop/rspec_rails_cops.rb index a1a4b45f..c436b81d 100644 --- a/lib/rubocop/cop/rspec_rails_cops.rb +++ b/lib/rubocop/cop/rspec_rails_cops.rb @@ -1,137 +1,13 @@ # frozen_string_literal: true -require_relative 'rspec/capybara/current_path_expectation' -require_relative 'rspec/capybara/feature_methods' -require_relative 'rspec/capybara/match_style' -require_relative 'rspec/capybara/negation_matcher' -require_relative 'rspec/capybara/specific_actions' -require_relative 'rspec/capybara/specific_finders' -require_relative 'rspec/capybara/specific_matcher' -require_relative 'rspec/capybara/visibility_matcher' - -require_relative 'rspec/factory_bot/attribute_defined_statically' -require_relative 'rspec/factory_bot/consistent_parentheses_style' -require_relative 'rspec/factory_bot/create_list' -require_relative 'rspec/factory_bot/factory_class_name' -require_relative 'rspec/factory_bot/factory_name_style' -require_relative 'rspec/factory_bot/syntax_methods' - -require_relative 'rspec/rails/avoid_setup_hook' -require_relative 'rspec/rails/have_http_status' -require_relative 'rspec/rails/negation_be_valid' +require_relative 'rspec_rails/avoid_setup_hook' +require_relative 'rspec_rails/have_http_status' +require_relative 'rspec_rails/negation_be_valid' begin - require_relative 'rspec/rails/http_status' + require_relative 'rspec_rails/http_status' rescue LoadError - # Rails/HttpStatus cannot be loaded if rack/utils is unavailable. + # RSpecRails/HttpStatus cannot be loaded if rack/utils is unavailable. end -require_relative 'rspec/rails/inferred_spec_type' -require_relative 'rspec/rails/minitest_assertions' -require_relative 'rspec/rails/travel_around' - -require_relative 'rspec/align_left_let_brace' -require_relative 'rspec/align_right_let_brace' -require_relative 'rspec/any_instance' -require_relative 'rspec/around_block' -require_relative 'rspec/be' -require_relative 'rspec/be_empty' -require_relative 'rspec/be_eq' -require_relative 'rspec/be_eql' -require_relative 'rspec/be_nil' -require_relative 'rspec/before_after_all' -require_relative 'rspec/change_by_zero' -require_relative 'rspec/class_check' -require_relative 'rspec/contain_exactly' -require_relative 'rspec/context_method' -require_relative 'rspec/context_wording' -require_relative 'rspec/describe_class' -require_relative 'rspec/describe_method' -require_relative 'rspec/describe_symbol' -require_relative 'rspec/described_class' -require_relative 'rspec/described_class_module_wrapping' -require_relative 'rspec/dialect' -require_relative 'rspec/duplicated_metadata' -require_relative 'rspec/empty_example_group' -require_relative 'rspec/empty_hook' -require_relative 'rspec/empty_line_after_example' -require_relative 'rspec/empty_line_after_example_group' -require_relative 'rspec/empty_line_after_final_let' -require_relative 'rspec/empty_line_after_hook' -require_relative 'rspec/empty_line_after_subject' -require_relative 'rspec/empty_metadata' -require_relative 'rspec/eq' -require_relative 'rspec/example_length' -require_relative 'rspec/example_without_description' -require_relative 'rspec/example_wording' -require_relative 'rspec/excessive_docstring_spacing' -require_relative 'rspec/expect_actual' -require_relative 'rspec/expect_change' -require_relative 'rspec/expect_in_hook' -require_relative 'rspec/expect_output' -require_relative 'rspec/file_path' -require_relative 'rspec/focus' -require_relative 'rspec/hook_argument' -require_relative 'rspec/hooks_before_examples' -require_relative 'rspec/identical_equality_assertion' -require_relative 'rspec/implicit_block_expectation' -require_relative 'rspec/implicit_expect' -require_relative 'rspec/implicit_subject' -require_relative 'rspec/indexed_let' -require_relative 'rspec/instance_spy' -require_relative 'rspec/instance_variable' -require_relative 'rspec/is_expected_specify' -require_relative 'rspec/it_behaves_like' -require_relative 'rspec/iterated_expectation' -require_relative 'rspec/leading_subject' -require_relative 'rspec/leaky_constant_declaration' -require_relative 'rspec/let_before_examples' -require_relative 'rspec/let_setup' -require_relative 'rspec/match_array' -require_relative 'rspec/message_chain' -require_relative 'rspec/message_expectation' -require_relative 'rspec/message_spies' -require_relative 'rspec/metadata_style' -require_relative 'rspec/missing_example_group_argument' -require_relative 'rspec/multiple_describes' -require_relative 'rspec/multiple_expectations' -require_relative 'rspec/multiple_memoized_helpers' -require_relative 'rspec/multiple_subjects' -require_relative 'rspec/named_subject' -require_relative 'rspec/nested_groups' -require_relative 'rspec/no_expectation_example' -require_relative 'rspec/not_to_not' -require_relative 'rspec/overwriting_setup' -require_relative 'rspec/pending' -require_relative 'rspec/pending_without_reason' -require_relative 'rspec/predicate_matcher' -require_relative 'rspec/receive_counts' -require_relative 'rspec/receive_messages' -require_relative 'rspec/receive_never' -require_relative 'rspec/redundant_around' -require_relative 'rspec/redundant_predicate_matcher' -require_relative 'rspec/remove_const' -require_relative 'rspec/repeated_description' -require_relative 'rspec/repeated_example' -require_relative 'rspec/repeated_example_group_body' -require_relative 'rspec/repeated_example_group_description' -require_relative 'rspec/repeated_include_example' -require_relative 'rspec/repeated_subject_call' -require_relative 'rspec/return_from_stub' -require_relative 'rspec/scattered_let' -require_relative 'rspec/scattered_setup' -require_relative 'rspec/shared_context' -require_relative 'rspec/shared_examples' -require_relative 'rspec/single_argument_message_chain' -require_relative 'rspec/skip_block_inside_example' -require_relative 'rspec/sort_metadata' -require_relative 'rspec/spec_file_path_format' -require_relative 'rspec/spec_file_path_suffix' -require_relative 'rspec/stubbed_mock' -require_relative 'rspec/subject_declaration' -require_relative 'rspec/subject_stub' -require_relative 'rspec/unspecified_exception' -require_relative 'rspec/variable_definition' -require_relative 'rspec/variable_name' -require_relative 'rspec/verified_double_reference' -require_relative 'rspec/verified_doubles' -require_relative 'rspec/void_expect' -require_relative 'rspec/yield' +require_relative 'rspec_rails/inferred_spec_type' +require_relative 'rspec_rails/minitest_assertions' +require_relative 'rspec_rails/travel_around' diff --git a/lib/rubocop/rspec_rails/config_formatter.rb b/lib/rubocop/rspec_rails/config_formatter.rb index f41985e4..4508d6e3 100644 --- a/lib/rubocop/rspec_rails/config_formatter.rb +++ b/lib/rubocop/rspec_rails/config_formatter.rb @@ -3,28 +3,13 @@ require 'yaml' module RuboCop - module RSpec + module RSpecRails # Builds a YAML config file from two config hashes class ConfigFormatter - EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze - SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails) - EXTRACTED_COPS = %( - RSpec/Capybara/CurrentPathExpectation - RSpec/Capybara/MatchStyle - RSpec/Capybara/NegationMatcher - RSpec/Capybara/SpecificActions - RSpec/Capybara/SpecificFinders - RSpec/Capybara/SpecificMatcher - RSpec/Capybara/VisibilityMatcher - RSpec/FactoryBot/AttributeDefinedStatically - RSpec/FactoryBot/ConsistentParenthesesStyle - RSpec/FactoryBot/CreateList - RSpec/FactoryBot/FactoryClassName - RSpec/FactoryBot/FactoryNameStyle - RSpec/FactoryBot/SyntaxMethods - ) - AMENDMENTS = %(Metrics/BlockLength) - COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/' + EXTENSION_ROOT_DEPARTMENT = %r{^(RSpecRails/)}.freeze + SUBDEPARTMENTS = [].freeze + AMENDMENTS = [].freeze + COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/' def initialize(config, descriptions) @config = config @@ -34,7 +19,6 @@ def initialize(config, descriptions) def dump YAML.dump(unified_config) .gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1") - .gsub(*AMENDMENTS, "\n\\0") .gsub(/^(\s+)- /, '\1 - ') .gsub('"~"', '~') end @@ -44,7 +28,6 @@ def dump def unified_config cops.each_with_object(config.dup) do |cop, unified| next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop) - next if EXTRACTED_COPS.include?(cop) replace_nil(unified[cop]) unified[cop].merge!(descriptions.fetch(cop)) diff --git a/lib/rubocop/rspec_rails/description_extractor.rb b/lib/rubocop/rspec_rails/description_extractor.rb index f63cbc3a..c524694c 100644 --- a/lib/rubocop/rspec_rails/description_extractor.rb +++ b/lib/rubocop/rspec_rails/description_extractor.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RuboCop - module RSpec + module RSpecRails # Extracts cop descriptions from YARD docstrings class DescriptionExtractor def initialize(yardocs) @@ -10,7 +10,7 @@ def initialize(yardocs) def to_h code_objects - .select(&:rspec_cop?) + .select(&:rspec_rails_cop?) .map(&:configuration) .reduce(:merge) end @@ -21,19 +21,18 @@ def to_h # Decorator of a YARD code object for working with documented rspec cops class CodeObject - RSPEC_COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base' + RSPEC_RAILS_COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base' RUBOCOP_COP_CLASS_NAME = 'RuboCop::Cop::Base' - RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec' def initialize(yardoc) @yardoc = yardoc end - # Test if the YARD code object documents a concrete rspec cop class + # Test if the YARD code object documents a concrete cop class # # @return [Boolean] - def rspec_cop? - cop_subclass? && !abstract? && rspec_cop_namespace? + def rspec_rails_cop? + cop_subclass? && !abstract? end # Configuration for the documented cop that would live in default.yml @@ -53,16 +52,12 @@ def description yardoc.docstring.split("\n\n").first.to_s end - def rspec_cop_namespace? - documented_constant.start_with?(RSPEC_NAMESPACE) - end - def documented_constant yardoc.to_s end def cop_subclass? - yardoc.superclass.path == RSPEC_COP_CLASS_NAME || + yardoc.superclass.path == RSPEC_RAILS_COP_CLASS_NAME || yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME end diff --git a/lib/rubocop/rspec_rails/version.rb b/lib/rubocop/rspec_rails/version.rb index 63cf8b7d..16776987 100644 --- a/lib/rubocop/rspec_rails/version.rb +++ b/lib/rubocop/rspec_rails/version.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true module RuboCop - module RSpec - # Version information for the RSpec RuboCop plugin. + module RSpecRails + # Version information for the RSpec Rails RuboCop plugin. module Version - STRING = '2.27.1' + STRING = '2.28.0' end end end diff --git a/rubocop-rspec_rails.gemspec b/rubocop-rspec_rails.gemspec index 7e24ca3f..58f12095 100644 --- a/rubocop-rspec_rails.gemspec +++ b/rubocop-rspec_rails.gemspec @@ -1,25 +1,22 @@ # frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('lib', __dir__) -require 'rubocop/rspec/version' +require 'rubocop/rspec_rails/version' Gem::Specification.new do |spec| - spec.name = 'rubocop-rspec' - spec.summary = 'Code style checking for RSpec files' + spec.name = 'rubocop-rspec_rails' + spec.summary = 'Code style checking for RSpec Rails files' spec.description = <<~DESCRIPTION - Code style checking for RSpec files. + Code style checking for RSpec Rails files. A plugin for the RuboCop code style enforcing & linting tool. DESCRIPTION - spec.homepage = 'https://github.com/rubocop/rubocop-rspec' - spec.authors = ['John Backus', 'Ian MacLeod', 'Nils Gemeinhardt'] - spec.email = [ - 'johncbackus@gmail.com', - 'ian@nevir.net', - 'git@nilsgemeinhardt.de' + spec.homepage = 'https://github.com/rubocop/rubocop-rspec_rails' + spec.authors = [ + 'Benjamin Quorning', 'Phil Pirozhkov', 'Maxim Krizhanovsky', 'Yudai Takada' ] spec.licenses = ['MIT'] - spec.version = RuboCop::RSpec::Version::STRING + spec.version = RuboCop::RSpecRails::Version::STRING spec.platform = Gem::Platform::RUBY spec.required_ruby_version = '>= 2.7.0' @@ -32,12 +29,11 @@ Gem::Specification.new do |spec| spec.extra_rdoc_files = ['MIT-LICENSE.md', 'README.md'] spec.metadata = { - 'changelog_uri' => 'https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md', - 'documentation_uri' => 'https://docs.rubocop.org/rubocop-rspec/', + 'changelog_uri' => 'https://github.com/rubocop/rubocop-rspec_rails/blob/master/CHANGELOG.md', + 'documentation_uri' => 'https://docs.rubocop.org/rubocop-rspec_rails/', 'rubygems_mfa_required' => 'true' } spec.add_runtime_dependency 'rubocop', '~> 1.40' - spec.add_runtime_dependency 'rubocop-capybara', '~> 2.17' - spec.add_runtime_dependency 'rubocop-factory_bot', '~> 2.22' + spec.add_runtime_dependency 'rubocop-rspec', '~> 2.27' end diff --git a/spec/project/default_config_spec.rb b/spec/project/default_config_spec.rb index 7b02deb7..881a5ac4 100644 --- a/spec/project/default_config_spec.rb +++ b/spec/project/default_config_spec.rb @@ -7,25 +7,20 @@ let(:namespaces) do { - 'rspec' => 'RSpec', - 'capybara' => 'RSpec/Capybara', - 'factory_bot' => 'RSpec/FactoryBot', - 'rails' => 'RSpec/Rails' + 'rspec_rails' => 'RSpecRails' } end let(:cop_names) do - glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec', - '{,capybara,factory_bot,rails}', '*.rb') - cop_names = - Pathname.glob(glob).map do |file| - file_name = file.basename('.rb').to_s - cop_name = file_name.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase } - namespace = namespaces[file.dirname.basename.to_s] - "#{namespace}/#{cop_name}" - end + glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec_rails', '*.rb') + cop_names = Pathname.glob(glob).map do |file| + file_name = file.basename('.rb').to_s + cop_name = file_name.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase } + namespace = namespaces[file.dirname.basename.to_s] + "#{namespace}/#{cop_name}" + end - cop_names - %w[RSpec/Base] + cop_names - %w[RSpecRails/Base] end let(:config_keys) do @@ -42,23 +37,23 @@ def cop_configuration(config_key) end end - it 'has configuration for all cops and amendments' do + it 'has configuration for all cops' do expect(default_config.keys) - .to contain_exactly(*config_keys, 'Metrics/BlockLength') + .to match_array(config_keys) end it 'sorts configuration keys alphabetically with nested namespaces last' do - rspec_keys = default_config.keys.select { |key| key.start_with?('RSpec') } - namespaced_rspec_keys = rspec_keys.select do |key| - key.start_with?(*(namespaces.values - ['RSpec'])) + keys = default_config.keys.select { |key| key.start_with?('RSpecRails') } + namespaced_keys = keys.select do |key| + key.start_with?(*(namespaces.values - ['RSpecRails'])) end - expected = rspec_keys.sort_by do |key| - namespaced = namespaced_rspec_keys.include?(key) ? 1 : 0 + expected = keys.sort_by do |key| + namespaced = namespaced_keys.include?(key) ? 1 : 0 "#{namespaced} #{key}" end - rspec_keys.each_with_index do |key, idx| + keys.each_with_index do |key, idx| expect(key).to eq expected[idx] end end @@ -81,17 +76,4 @@ def cop_configuration(config_key) expect(cop_configuration('Enabled')) .to all be(true).or(be(false)).or(eq('pending')) end - - it 'does not include unnecessary `SafeAutoCorrect: false`' do - cop_names.each do |cop_name| - next unless default_config.dig(cop_name, 'Safe') == false - - safe_autocorrect = default_config.dig(cop_name, 'SafeAutoCorrect') - - expect(safe_autocorrect).not_to( - be(false), - "`#{cop_name}` has unnecessary `SafeAutoCorrect: false` config." - ) - end - end end diff --git a/spec/rubocop/cop/rspec_rails/avoid_setup_hook_spec.rb b/spec/rubocop/cop/rspec_rails/avoid_setup_hook_spec.rb index 01c95275..ca13b963 100644 --- a/spec/rubocop/cop/rspec_rails/avoid_setup_hook_spec.rb +++ b/spec/rubocop/cop/rspec_rails/avoid_setup_hook_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::AvoidSetupHook do +RSpec.describe RuboCop::Cop::RSpecRails::AvoidSetupHook do it 'registers an offense for `setup`' do expect_offense(<<~RUBY) setup do diff --git a/spec/rubocop/cop/rspec_rails/have_http_status_spec.rb b/spec/rubocop/cop/rspec_rails/have_http_status_spec.rb index 9eebeda7..20961b47 100644 --- a/spec/rubocop/cop/rspec_rails/have_http_status_spec.rb +++ b/spec/rubocop/cop/rspec_rails/have_http_status_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::HaveHttpStatus do +RSpec.describe RuboCop::Cop::RSpecRails::HaveHttpStatus do it 'registers an offense for `expect(response.status).to be(200)`' do expect_offense(<<~RUBY) it { expect(response.status).to be(200) } diff --git a/spec/rubocop/cop/rspec_rails/http_status_spec.rb b/spec/rubocop/cop/rspec_rails/http_status_spec.rb index eba7e2a0..a61abb74 100644 --- a/spec/rubocop/cop/rspec_rails/http_status_spec.rb +++ b/spec/rubocop/cop/rspec_rails/http_status_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::HttpStatus do +RSpec.describe RuboCop::Cop::RSpecRails::HttpStatus do context 'when EnforcedStyle is `symbolic`' do let(:cop_config) { { 'EnforcedStyle' => 'symbolic' } } diff --git a/spec/rubocop/cop/rspec_rails/inferred_spec_type_spec.rb b/spec/rubocop/cop/rspec_rails/inferred_spec_type_spec.rb index e9c0da51..0faf312d 100644 --- a/spec/rubocop/cop/rspec_rails/inferred_spec_type_spec.rb +++ b/spec/rubocop/cop/rspec_rails/inferred_spec_type_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::InferredSpecType do +RSpec.describe RuboCop::Cop::RSpecRails::InferredSpecType do describe 'with necessary type in keyword arguments' do it 'does not register any offense' do expect_no_offenses(<<~RUBY) diff --git a/spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb b/spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb index f410a2ee..179330c2 100644 --- a/spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb +++ b/spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::MinitestAssertions do +RSpec.describe RuboCop::Cop::RSpecRails::MinitestAssertions do context 'with equal assertions' do it 'registers an offense when using `assert_equal`' do expect_offense(<<~RUBY) diff --git a/spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb b/spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb index 0c6fec2c..d35bf4a4 100644 --- a/spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb +++ b/spec/rubocop/cop/rspec_rails/negation_be_valid_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::NegationBeValid do +RSpec.describe RuboCop::Cop::RSpecRails::NegationBeValid do let(:cop_config) { { 'EnforcedStyle' => enforced_style } } context 'with EnforcedStyle `not_to`' do diff --git a/spec/rubocop/cop/rspec_rails/travel_around_spec.rb b/spec/rubocop/cop/rspec_rails/travel_around_spec.rb index ae1c2944..52401f3f 100644 --- a/spec/rubocop/cop/rspec_rails/travel_around_spec.rb +++ b/spec/rubocop/cop/rspec_rails/travel_around_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::RSpec::Rails::TravelAround do +RSpec.describe RuboCop::Cop::RSpecRails::TravelAround do context 'with `freeze_time` in `before`' do it 'registers no offense' do expect_no_offenses(<<~RUBY) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c80a7d1..895541a3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require 'rubocop' -require 'rubocop/rspec/support' +require 'rubocop/rspec/shared_contexts/default_rspec_language_config_context' +require 'rubocop/rspec/support' # `expect_offense` etc require 'simplecov' unless ENV['NO_COVERAGE'] @@ -9,7 +10,8 @@ module SpecHelper ROOT = Pathname.new(__dir__).parent.freeze end -spec_helper_glob = '{support,shared,../lib/rubocop/rspec/shared_contexts}/*.rb' +spec_helper_glob = + '{support,shared,../lib/rubocop/rspec/shared_contexts}/*.rb' Dir .glob(File.expand_path(spec_helper_glob, __dir__)) .sort @@ -18,7 +20,7 @@ module SpecHelper RSpec.configure do |config| # Set metadata so smoke tests are run on all cop specs config.define_derived_metadata( - file_path: %r{/spec/rubocop/cop/rspec/(?!mixin/)} + file_path: %r{/spec/rubocop/cop/} ) do |meta| meta[:type] = :cop_spec end @@ -48,4 +50,4 @@ module SpecHelper $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require 'rubocop-rspec' +require 'rubocop-rspec_rails' diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index 2010920a..9936db9f 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'rubocop' -require 'rubocop-rspec' +require 'rubocop-rspec_rails' require 'rubocop/cops_documentation_generator' require 'yard' @@ -12,65 +12,10 @@ end desc 'Generate docs of all cops departments' task generate_cops_documentation: :yard_for_generate_documentation do - RuboCop::Cop::Registry.with_temporary_global do - global = RuboCop::Cop::Registry.global - # We set a constant for the old cop class, and this skips the - # `Base.inherited` hook that enlists those old cops. - %w[ - RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation - RuboCop::Cop::RSpec::Capybara::MatchStyle - RuboCop::Cop::RSpec::Capybara::NegationMatcher - RuboCop::Cop::RSpec::Capybara::SpecificActions - RuboCop::Cop::RSpec::Capybara::SpecificFinders - RuboCop::Cop::RSpec::Capybara::SpecificMatcher - RuboCop::Cop::RSpec::Capybara::VisibilityMatcher - ].each do |extracted_cop| - cop = Class.const_get(extracted_cop) - class << cop - def badge - RuboCop::Cop::Badge.for(name) - end - - def name - super.sub('::Capybara::', '::RSpec::Capybara::') - end - - def department - :'RSpec/Capybara' - end - end - global.enlist(cop) - end - %w[ - RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically - RuboCop::Cop::RSpec::FactoryBot::ConsistentParenthesesStyle - RuboCop::Cop::RSpec::FactoryBot::CreateList - RuboCop::Cop::RSpec::FactoryBot::FactoryClassName - RuboCop::Cop::RSpec::FactoryBot::FactoryNameStyle - RuboCop::Cop::RSpec::FactoryBot::SyntaxMethods - ].each do |extracted_cop| - cop = Class.const_get(extracted_cop) - class << cop - def badge - RuboCop::Cop::Badge.for(name) - end - - def name - super.sub('::FactoryBot::', '::RSpec::FactoryBot::') - end - - def department - :'RSpec/FactoryBot' - end - end - global.enlist(cop) - end - - generator = CopsDocumentationGenerator.new( - departments: %w[RSpec/Capybara RSpec/FactoryBot RSpec/Rails RSpec] - ) - generator.call - end + generator = CopsDocumentationGenerator.new( + departments: %w[RSpecRails] + ) + generator.call end desc 'Syntax check for the documentation comments'