diff --git a/CHANGELOG.md b/CHANGELOG.md index 21aba0806..2a29216b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Master (Unreleased) +- Remove extracted cops in `Capybara`, `FactoryBot` and `Rails` departments. ([@ydah]) + ## 2.29.2 (2024-05-02) - Fix beginless and endless range bug for RepeatedIncludeExample cop. ([@hasghari]) diff --git a/Rakefile b/Rakefile index c11b55cd6..6dc3b8f04 100644 --- a/Rakefile +++ b/Rakefile @@ -34,7 +34,7 @@ task :build_config do require 'rubocop/rspec/description_extractor' glob = File.join('lib', 'rubocop', 'cop', 'rspec', - '{,capybara,factory_bot,rails}', '*.rb') + '{,capybara}', '*.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 diff --git a/config/default.yml b/config/default.yml index 7ed394d9e..3d2fbb60b 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1011,13 +1011,6 @@ RSpec/Capybara: 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 @@ -1025,196 +1018,3 @@ RSpec/Capybara/FeatureMethods: 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. - Enabled: true - 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: - 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 - -RSpec/Rails/HaveHttpStatus: - Description: Checks that tests use `have_http_status` instead of equality matchers. - Enabled: pending - ResponseMethods: - - response - - last_response - SafeAutoCorrect: false - VersionAdded: '2.12' - VersionChanged: '2.27' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HaveHttpStatus - -RSpec/Rails/HttpStatus: - Description: Enforces use of symbolic or numeric value to describe HTTP status. - Enabled: true - EnforcedStyle: symbolic - SupportedStyles: - - numeric - - symbolic - - be_status - VersionAdded: '1.23' - VersionChanged: '2.20' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus - -RSpec/Rails/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 - Inferences: - channels: channel - controllers: controller - features: feature - generator: generator - helpers: helper - jobs: job - mailboxes: mailbox - mailers: mailer - models: model - requests: request - integration: request - api: request - routing: routing - system: system - views: view - -RSpec/Rails/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 - -RSpec/Rails/NegationBeValid: - Description: Enforces use of `be_invalid` or `not_to` for negated be_valid. - Safe: false - EnforcedStyle: not_to - SupportedStyles: - - not_to - - be_invalid - Enabled: pending - VersionAdded: '2.23' - Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid - -RSpec/Rails/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 diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index db2d41988..2ab1a89d1 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -1,13 +1,10 @@ * 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:upgrade_to_version_3.adoc[Upgrade to 3.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 dd6fcfaa9..1e8f5be80 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -114,32 +114,6 @@ === 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] // END_COP_LIST diff --git a/docs/modules/ROOT/pages/cops_rspec_capybara.adoc b/docs/modules/ROOT/pages/cops_rspec_capybara.adoc index 937c34cea..6ea58f2b8 100644 --- a/docs/modules/ROOT/pages/cops_rspec_capybara.adoc +++ b/docs/modules/ROOT/pages/cops_rspec_capybara.adoc @@ -6,51 +6,6 @@ = RSpec/Capybara -== RSpec/Capybara/CurrentPathExpectation - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| Always -| 1.18 -| 2.0 -|=== - -Checks that no expectations are set on Capybara's `current_path`. - -The -https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher] -should be used on `page` to set expectations on Capybara's -current path, since it uses -https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality] -which ensures that preceding actions (like `click_link`) have -completed. - -This cop does not support autocorrection in some cases. - -=== Examples - -[source,ruby] ----- -# bad -expect(current_path).to eq('/callback') - -# good -expect(page).to have_current_path('/callback') - -# bad (does not support autocorrection) -expect(page.current_path).to match(variable) - -# good -expect(page).to have_current_path('/callback') ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/CurrentPathExpectation - == RSpec/Capybara/FeatureMethods |=== @@ -117,264 +72,3 @@ end === References * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods - -== RSpec/Capybara/MatchStyle - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.17 -| - -|=== - -Checks for usage of deprecated style methods. - -=== Examples - -==== when using `assert_style` - -[source,ruby] ----- -# bad -page.find(:css, '#first').assert_style(display: 'block') - -# good -page.find(:css, '#first').assert_matches_style(display: 'block') ----- - -==== when using `has_style?` - -[source,ruby] ----- -# bad -expect(page.find(:css, 'first') - .has_style?(display: 'block')).to be true - -# good -expect(page.find(:css, 'first') - .matches_style?(display: 'block')).to be true ----- - -==== when using `have_style` - -[source,ruby] ----- -# bad -expect(page).to have_style(display: 'block') - -# good -expect(page).to match_style(display: 'block') ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/MatchStyle - -== RSpec/Capybara/NegationMatcher - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.14 -| - -|=== - -Enforces use of `have_no_*` or `not_to` for negated expectations. - -=== Examples - -==== EnforcedStyle: not_to (default) - -[source,ruby] ----- -# bad -expect(page).to have_no_selector -expect(page).to have_no_css('a') - -# good -expect(page).not_to have_selector -expect(page).not_to have_css('a') ----- - -==== EnforcedStyle: have_no - -[source,ruby] ----- -# bad -expect(page).not_to have_selector -expect(page).not_to have_css('a') - -# good -expect(page).to have_no_selector -expect(page).to have_no_css('a') ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `not_to` -| `have_no`, `not_to` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/NegationMatcher - -== RSpec/Capybara/SpecificActions - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| No -| 2.14 -| - -|=== - -Checks for there is a more specific actions offered by Capybara. - -=== Examples - -[source,ruby] ----- -# bad -find('a').click -find('button.cls').click -find('a', exact_text: 'foo').click -find('div button').click - -# good -click_link -click_button(class: 'cls') -click_link(exact_text: 'foo') -find('div').click_button ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificActions - -== RSpec/Capybara/SpecificFinders - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.13 -| - -|=== - -Checks if there is a more specific finder offered by Capybara. - -=== Examples - -[source,ruby] ----- -# bad -find('#some-id') -find('[visible][id=some-id]') - -# good -find_by_id('some-id') -find_by_id('some-id', visible: true) ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificFinders - -== RSpec/Capybara/SpecificMatcher - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| No -| 2.12 -| - -|=== - -Checks for there is a more specific matcher offered by Capybara. - -=== Examples - -[source,ruby] ----- -# bad -expect(page).to have_selector('button') -expect(page).to have_no_selector('button.cls') -expect(page).to have_css('button') -expect(page).to have_no_css('a.cls', href: 'http://example.com') -expect(page).to have_css('table.cls') -expect(page).to have_css('select') -expect(page).to have_css('input', exact_text: 'foo') - -# good -expect(page).to have_button -expect(page).to have_no_button(class: 'cls') -expect(page).to have_button -expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com') -expect(page).to have_table(class: 'cls') -expect(page).to have_select -expect(page).to have_field('foo') ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/SpecificMatcher - -== RSpec/Capybara/VisibilityMatcher - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| No -| 1.39 -| 2.0 -|=== - -Checks for boolean visibility in Capybara finders. - -Capybara lets you find elements that match a certain visibility -using the `:visible` option. `:visible` accepts both boolean and -symbols as values, however using booleans can have unwanted -effects. `visible: false` does not find just invisible elements, -but both visible and invisible elements. For expressiveness and -clarity, use one of the # symbol values, `:all`, `:hidden` or -`:visible`. -Read more in -https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation]. - -=== Examples - -[source,ruby] ----- -# bad -expect(page).to have_selector('.foo', visible: false) -expect(page).to have_css('.foo', visible: true) -expect(page).to have_link('my link', visible: false) - -# good -expect(page).to have_selector('.foo', visible: :visible) -expect(page).to have_css('.foo', visible: :all) -expect(page).to have_link('my link', visible: :hidden) ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher diff --git a/docs/modules/ROOT/pages/cops_rspec_factorybot.adoc b/docs/modules/ROOT/pages/cops_rspec_factorybot.adoc deleted file mode 100644 index 580edbb3a..000000000 --- a/docs/modules/ROOT/pages/cops_rspec_factorybot.adoc +++ /dev/null @@ -1,361 +0,0 @@ -//// - Do NOT edit this file by hand directly, as it is automatically generated. - - Please make any necessary changes to the cop documentation within the source files themselves. -//// - -= RSpec/FactoryBot - -== RSpec/FactoryBot/AttributeDefinedStatically - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| Always -| 1.28 -| 2.23 -|=== - -Always declare attribute values as blocks. - -=== Examples - -[source,ruby] ----- -# bad -kind [:active, :rejected].sample - -# good -kind { [:active, :rejected].sample } - -# bad -closed_at 1.day.from_now - -# good -closed_at { 1.day.from_now } - -# bad -count 1 - -# good -count { 1 } ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| Include -| `+**/spec/factories.rb+`, `+**/spec/factories/**/*.rb+`, `+**/features/support/factories/**/*.rb+` -| Array -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/AttributeDefinedStatically - -== RSpec/FactoryBot/ConsistentParenthesesStyle - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.14 -| - -|=== - -Use a consistent style for parentheses in factory bot calls. - -=== Examples - -[source,ruby] ----- -# bad -create :user -build(:user) -create(:login) -create :login ----- - -==== `EnforcedStyle: require_parentheses` (default) - -[source,ruby] ----- -# good -create(:user) -create(:user) -create(:login) -build(:login) ----- - -==== `EnforcedStyle: omit_parentheses` - -[source,ruby] ----- -# good -create :user -build :user -create :login -create :login - -# also good -# when method name and first argument are not on same line -create( - :user -) -build( - :user, - name: 'foo' -) ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `require_parentheses` -| `require_parentheses`, `omit_parentheses` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/ConsistentParenthesesStyle - -== RSpec/FactoryBot/CreateList - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| Always -| 1.25 -| 2.23 -|=== - -Checks for create_list usage. - -This cop can be configured using the `EnforcedStyle` option - -=== Examples - -==== `EnforcedStyle: create_list` (default) - -[source,ruby] ----- -# bad -3.times { create :user } - -# good -create_list :user, 3 - -# bad -3.times { create :user, age: 18 } - -# good - index is used to alter the created models attributes -3.times { |n| create :user, age: n } - -# good - contains a method call, may return different values -3.times { create :user, age: rand } ----- - -==== `EnforcedStyle: n_times` - -[source,ruby] ----- -# bad -create_list :user, 3 - -# good -3.times { create :user } ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| Include -| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/spec/factories.rb+`, `+**/spec/factories/**/*.rb+`, `+**/features/support/factories/**/*.rb+` -| Array - -| EnforcedStyle -| `create_list` -| `create_list`, `n_times` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/CreateList - -== RSpec/FactoryBot/FactoryClassName - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| Always -| 1.37 -| 2.23 -|=== - -Use string value when setting the class attribute explicitly. - -This cop would promote faster tests by lazy-loading of -application files. Also, this could help you suppress potential -bugs in combination with external libraries by avoiding a preload -of application files from the factory files. - -=== Examples - -[source,ruby] ----- -# bad -factory :foo, class: Foo do -end - -# good -factory :foo, class: 'Foo' do -end ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| Include -| `+**/spec/factories.rb+`, `+**/spec/factories/**/*.rb+`, `+**/features/support/factories/**/*.rb+` -| Array -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName - -== RSpec/FactoryBot/FactoryNameStyle - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.16 -| - -|=== - -Checks for name style for argument of FactoryBot::Syntax::Methods. - -=== Examples - -==== EnforcedStyle: symbol (default) - -[source,ruby] ----- -# bad -create('user') -build "user", username: "NAME" - -# good -create(:user) -build :user, username: "NAME" ----- - -==== EnforcedStyle: string - -[source,ruby] ----- -# bad -create(:user) -build :user, username: "NAME" - -# good -create('user') -build "user", username: "NAME" ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `symbol` -| `symbol`, `string` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryNameStyle - -== RSpec/FactoryBot/SyntaxMethods - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always (Unsafe) -| 2.7 -| - -|=== - -Use shorthands from `FactoryBot::Syntax::Methods` in your specs. - -=== Safety - -The autocorrection is marked as unsafe because the cop -cannot verify whether you already include -`FactoryBot::Syntax::Methods` in your test suite. - -If you're using Rails, add the following configuration to -`spec/support/factory_bot.rb` and be sure to require that file -in `rails_helper.rb`: - -[source,ruby] ----- -RSpec.configure do |config| - config.include FactoryBot::Syntax::Methods -end ----- - -If you're not using Rails: - -[source,ruby] ----- -RSpec.configure do |config| - config.include FactoryBot::Syntax::Methods - - config.before(:suite) do - FactoryBot.find_definitions - end -end ----- - -=== Examples - -[source,ruby] ----- -# bad -FactoryBot.create(:bar) -FactoryBot.build(:bar) -FactoryBot.attributes_for(:bar) - -# good -create(:bar) -build(:bar) -attributes_for(:bar) ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/SyntaxMethods diff --git a/docs/modules/ROOT/pages/cops_rspec_rails.adoc b/docs/modules/ROOT/pages/cops_rspec_rails.adoc deleted file mode 100644 index af981778f..000000000 --- a/docs/modules/ROOT/pages/cops_rspec_rails.adoc +++ /dev/null @@ -1,422 +0,0 @@ -//// - Do NOT edit this file by hand directly, as it is automatically generated. - - Please make any necessary changes to the cop documentation within the source files themselves. -//// - -= RSpec/Rails - -== RSpec/Rails/AvoidSetupHook - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.4 -| - -|=== - -Checks that tests use RSpec `before` hook over Rails `setup` -method. - -=== Examples - -[source,ruby] ----- -# bad -setup do - allow(foo).to receive(:bar) -end - -# good -before do - allow(foo).to receive(:bar) -end ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/AvoidSetupHook - -== RSpec/Rails/HaveHttpStatus - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always (Unsafe) -| 2.12 -| 2.27 -|=== - -Checks that tests use `have_http_status` instead of equality matchers. - -=== Examples - -==== ResponseMethods: ['response', 'last_response'] (default) - -[source,ruby] ----- -# 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) ----- - -==== ResponseMethods: ['foo_response'] - -[source,ruby] ----- -# 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) ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| ResponseMethods -| `response`, `last_response` -| Array -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HaveHttpStatus - -== RSpec/Rails/HttpStatus - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Enabled -| Yes -| Always -| 1.23 -| 2.20 -|=== - -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`. - -=== Examples - -==== `EnforcedStyle: symbolic` (default) - -[source,ruby] ----- -# 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 } ----- - -==== `EnforcedStyle: numeric` - -[source,ruby] ----- -# 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 } ----- - -==== `EnforcedStyle: be_status` - -[source,ruby] ----- -# 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 } ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `symbolic` -| `numeric`, `symbolic`, `be_status` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/HttpStatus - -== RSpec/Rails/InferredSpecType - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| No -| Always (Unsafe) -| 2.14 -| - -|=== - -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. - -=== Examples - -[source,ruby] ----- -# 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 ----- - -==== `Inferences` configuration - -[source,ruby] ----- -# .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 ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| Inferences -| `{"channels"=>"channel", "controllers"=>"controller", "features"=>"feature", "generator"=>"generator", "helpers"=>"helper", "jobs"=>"job", "mailboxes"=>"mailbox", "mailers"=>"mailer", "models"=>"model", "requests"=>"request", "integration"=>"request", "api"=>"request", "routing"=>"routing", "system"=>"system", "views"=>"view"}` -| -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/InferredSpecType - -== RSpec/Rails/MinitestAssertions - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| Yes -| Always -| 2.17 -| - -|=== - -Check if using Minitest-like matchers. - -Check the use of minitest-like matchers -starting with `assert_` or `refute_`. - -=== Examples - -[source,ruby] ----- -# 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) ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/MinitestAssertions - -== RSpec/Rails/NegationBeValid - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| No -| Always (Unsafe) -| 2.23 -| - -|=== - -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``. - -=== Examples - -==== EnforcedStyle: not_to (default) - -[source,ruby] ----- -# 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 ----- - -==== EnforcedStyle: be_invalid - -[source,ruby] ----- -# 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 ----- - -=== Configurable attributes - -|=== -| Name | Default value | Configurable values - -| EnforcedStyle -| `not_to` -| `not_to`, `be_invalid` -|=== - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/NegationBeValid - -== RSpec/Rails/TravelAround - -|=== -| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed - -| Pending -| No -| Always (Unsafe) -| 2.19 -| - -|=== - -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`. - -=== Examples - -[source,ruby] ----- -# bad -around do |example| - freeze_time do - example.run - end -end - -# good -before { freeze_time } ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Rails/TravelAround diff --git a/docs/modules/ROOT/pages/departments.adoc b/docs/modules/ROOT/pages/departments.adoc deleted file mode 100644 index e35778b6e..000000000 --- a/docs/modules/ROOT/pages/departments.adoc +++ /dev/null @@ -1,80 +0,0 @@ -= Departments - -RuboCop RSpec currently has four departments: - -* xref:cops_rspec.adoc[RSpec]: This department checks for RSpec-specific code style. -* xref:cops_rspec_capybara.adoc[RSpec/Capybara]: This department checks for Capybara-specific code style. -* xref:cops_rspec_factorybot.adoc[RSpec/FactoryBot]: This department checks for factory_bot-specific code style. -* xref:cops_rspec_rails.adoc[RSpec/Rails]: This department checks for RSpec-specific code style in Rails applications. - -Each department has its own set of cops. You can enable or disable individual cops within each department. If your project doesn't use factory_bot, and uses Sinatra and not Rails, you can disable the RSpec/FactoryBot and RSpec/Rails departments in your `.rubocop.yml` file: - -[source,yaml] ----- -RSpec/FactoryBot: - Enabled: false - -RSpec/Rails: - Enabled: false ----- - -== Planned to extract to separate gems - -There are plans for extracting the following three departments before RuboCop RSpec v3.0: - -[cols="1, 1, 1"] -|=== -|Department |Extract to |Status - -|RSpec/Capybara -|https://github.com/rubocop/rubocop-capybara[rubocop-capybara] -|Extracted in https://github.com/rubocop/rubocop-rspec/releases/tag/v2.18.0[v2.18.0] - -|RSpec/FactoryBot -|https://github.com/rubocop/rubocop-factory_bot[rubocop-factory_bot] -|Extracted in https://github.com/rubocop/rubocop-rspec/releases/tag/v2.22.0[v2.22.0] - -|RSpec/Rails -|rubocop-rspec_rails -|Extracted in https://github.com/rubocop/rubocop-rspec/releases/tag/v2.28.0[v2.28.0] -|=== - -=== Migration manual - -If you are using the RSpec/Capybara, RSpec/FactoryBot, or RSpec/Rails departments, you need to install the corresponding gem and add it to your `.rubocop.yml` file. - -For example, if you are using the RSpec/Capybara department, you need to install the `rubocop-capybara` gem and add it to your `.rubocop.yml` file: - -[source,ruby] ----- -# Gemfile -group :test do - gem 'rubocop-rspec' - gem 'rubocop-capybara' -end ----- - -[source,yaml] ----- -Capybara: - Enabled: true ----- - -And you need to disable the old department in your `.rubocop.yml` file: - -[source,yaml] ----- -RSpec/Capybara: - Enabled: false ----- - -For another example, if you are not using these departments, you don't need to do anything. -And when you update to RuboCop RSpec v3.0.0, you need to remove the old departments from your `.rubocop.yml` file, e.g.: - -[source,yaml] ----- -RSpec/Capybara: - Enabled: false -RSpec/FactoryBot: - Enabled: false ----- diff --git a/docs/modules/ROOT/pages/upgrade_to_version_3.adoc b/docs/modules/ROOT/pages/upgrade_to_version_3.adoc new file mode 100644 index 000000000..d0ad8adfd --- /dev/null +++ b/docs/modules/ROOT/pages/upgrade_to_version_3.adoc @@ -0,0 +1,51 @@ += Upgrade to Version 3.x +:doctype: book + +== Configuration File Update + +In version 3.x: + + - cop departments are extracted to another gem. (`Capybara`, `FactoryBot`, `Rails`) + +[discrete] +=== Extraction of cop departments. (`Capybara`, `FactoryBot`, `Rails`) + +If you are using the RSpec/Capybara, RSpec/FactoryBot, or RSpec/Rails departments, you need to install the corresponding gem and add it to your `.rubocop.yml` file. + +For example, if you are using the RSpec/Capybara department, you need to install the `rubocop-capybara` gem and add it to your `.rubocop.yml` file: + +[source,ruby] +---- +# Gemfile +group :test do + gem 'rubocop-rspec' + gem 'rubocop-capybara' +end +---- + +[source,yaml] +---- +Capybara: + Enabled: true +---- + +And you need to remove the old department in your `.rubocop.yml` file: + +[source,yaml] +---- +RSpec/Capybara: + Enabled: false +---- + +For another example, if you are not using these departments, you don't need to do anything. +And when you update to RuboCop RSpec v3.0.0, you need to remove the old departments from your `.rubocop.yml` file, e.g.: + +[source,yaml] +---- +RSpec/Capybara: + Enabled: false +RSpec/FactoryBot: + Enabled: false +RSpec/Rails: + Enabled: false +---- diff --git a/lib/rubocop-rspec.rb b/lib/rubocop-rspec.rb index fffc0a2a4..c3a7834fd 100644 --- a/lib/rubocop-rspec.rb +++ b/lib/rubocop-rspec.rb @@ -4,8 +4,6 @@ require 'yaml' require 'rubocop' -require 'rubocop-capybara' -require 'rubocop-factory_bot' require_relative 'rubocop/rspec' require_relative 'rubocop/rspec/inject' @@ -39,9 +37,6 @@ require_relative 'rubocop/rspec/example_group' require_relative 'rubocop/rspec/hook' -# need after `require 'rubocop/cop/rspec/base'`` -require 'rubocop-rspec_rails' - RuboCop::RSpec::Inject.defaults! require_relative 'rubocop/cop/rspec_cops' @@ -58,12 +53,4 @@ def autocorrect_incompatible_with 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) diff --git a/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb b/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb deleted file mode 100644 index 41fcd2170..000000000 --- a/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks that no expectations are set on Capybara's `current_path`. - # # - # # The - # # https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher] - # # should be used on `page` to set expectations on Capybara's - # # current path, since it uses - # # https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality] - # # which ensures that preceding actions (like `click_link`) have - # # completed. - # # - # # This cop does not support autocorrection in some cases. - # # - # # @example - # # # bad - # # expect(current_path).to eq('/callback') - # # - # # # good - # # expect(page).to have_current_path('/callback') - # # - # # # bad (does not support autocorrection) - # # expect(page.current_path).to match(variable) - # # - # # # good - # # expect(page).to have_current_path('/callback') - # # - # class CurrentPathExpectation < ::RuboCop::Cop::Base; end - CurrentPathExpectation = - ::RuboCop::Cop::Capybara::CurrentPathExpectation - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/match_style.rb b/lib/rubocop/cop/rspec/capybara/match_style.rb deleted file mode 100644 index b18102d45..000000000 --- a/lib/rubocop/cop/rspec/capybara/match_style.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks for usage of deprecated style methods. - # # - # # @example when using `assert_style` - # # # bad - # # page.find(:css, '#first').assert_style(display: 'block') - # # - # # # good - # # page.find(:css, '#first').assert_matches_style(display: 'block') - # # - # # @example when using `has_style?` - # # # bad - # # expect(page.find(:css, 'first') - # # .has_style?(display: 'block')).to be true - # # - # # # good - # # expect(page.find(:css, 'first') - # # .matches_style?(display: 'block')).to be true - # # - # # @example when using `have_style` - # # # bad - # # expect(page).to have_style(display: 'block') - # # - # # # good - # # expect(page).to match_style(display: 'block') - # # - # class MatchStyle < ::RuboCop::Cop::Base; end - MatchStyle = ::RuboCop::Cop::Capybara::MatchStyle - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/negation_matcher.rb b/lib/rubocop/cop/rspec/capybara/negation_matcher.rb deleted file mode 100644 index 7c9c51702..000000000 --- a/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Enforces use of `have_no_*` or `not_to` for negated expectations. - # # - # # @example EnforcedStyle: not_to (default) - # # # bad - # # expect(page).to have_no_selector - # # expect(page).to have_no_css('a') - # # - # # # good - # # expect(page).not_to have_selector - # # expect(page).not_to have_css('a') - # # - # # @example EnforcedStyle: have_no - # # # bad - # # expect(page).not_to have_selector - # # expect(page).not_to have_css('a') - # # - # # # good - # # expect(page).to have_no_selector - # # expect(page).to have_no_css('a') - # # - # class NegationMatcher < ::RuboCop::Cop::Base; end - NegationMatcher = ::RuboCop::Cop::Capybara::NegationMatcher - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/specific_actions.rb b/lib/rubocop/cop/rspec/capybara/specific_actions.rb deleted file mode 100644 index 93cea5a7f..000000000 --- a/lib/rubocop/cop/rspec/capybara/specific_actions.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks for there is a more specific actions offered by Capybara. - # # - # # @example - # # - # # # bad - # # find('a').click - # # find('button.cls').click - # # find('a', exact_text: 'foo').click - # # find('div button').click - # # - # # # good - # # click_link - # # click_button(class: 'cls') - # # click_link(exact_text: 'foo') - # # find('div').click_button - # # - # class SpecificActions < ::RuboCop::Cop::Base; end - SpecificActions = ::RuboCop::Cop::Capybara::SpecificActions - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/specific_finders.rb b/lib/rubocop/cop/rspec/capybara/specific_finders.rb deleted file mode 100644 index 41c346e5a..000000000 --- a/lib/rubocop/cop/rspec/capybara/specific_finders.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks if there is a more specific finder offered by Capybara. - # # - # # @example - # # # bad - # # find('#some-id') - # # find('[visible][id=some-id]') - # # - # # # good - # # find_by_id('some-id') - # # find_by_id('some-id', visible: true) - # # - # class SpecificFinders < ::RuboCop::Cop::Base; end - SpecificFinders = ::RuboCop::Cop::Capybara::SpecificFinders - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/specific_matcher.rb b/lib/rubocop/cop/rspec/capybara/specific_matcher.rb deleted file mode 100644 index e6f5fa4d6..000000000 --- a/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks for there is a more specific matcher offered by Capybara. - # # - # # @example - # # - # # # bad - # # expect(page).to have_selector('button') - # # expect(page).to have_no_selector('button.cls') - # # expect(page).to have_css('button') - # # expect(page).to have_no_css('a.cls', href: 'http://example.com') - # # expect(page).to have_css('table.cls') - # # expect(page).to have_css('select') - # # expect(page).to have_css('input', exact_text: 'foo') - # # - # # # good - # # expect(page).to have_button - # # expect(page).to have_no_button(class: 'cls') - # # expect(page).to have_button - # # expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com') - # # expect(page).to have_table(class: 'cls') - # # expect(page).to have_select - # # expect(page).to have_field('foo') - # # - # class SpecificMatcher < ::RuboCop::Cop::Base; end - SpecificMatcher = ::RuboCop::Cop::Capybara::SpecificMatcher - end - end - end -end diff --git a/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb b/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb deleted file mode 100644 index bb63f8b73..000000000 --- a/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Capybara - # @!parse - # # Checks for boolean visibility in Capybara finders. - # # - # # Capybara lets you find elements that match a certain visibility - # # using the `:visible` option. `:visible` accepts both boolean and - # # symbols as values, however using booleans can have unwanted - # # effects. `visible: false` does not find just invisible elements, - # # but both visible and invisible elements. For expressiveness and - # # clarity, use one of the # symbol values, `:all`, `:hidden` or - # # `:visible`. - # # Read more in - # # https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation]. - # # - # # @example - # # # bad - # # expect(page).to have_selector('.foo', visible: false) - # # expect(page).to have_css('.foo', visible: true) - # # expect(page).to have_link('my link', visible: false) - # # - # # # good - # # expect(page).to have_selector('.foo', visible: :visible) - # # expect(page).to have_css('.foo', visible: :all) - # # expect(page).to have_link('my link', visible: :hidden) - # # - # class VisibilityMatcher < ::RuboCop::Cop::Base; end - VisibilityMatcher = ::RuboCop::Cop::Capybara::VisibilityMatcher - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb b/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb deleted file mode 100644 index 60cbe185c..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Always declare attribute values as blocks. - # # - # # @example - # # # bad - # # kind [:active, :rejected].sample - # # - # # # good - # # kind { [:active, :rejected].sample } - # # - # # # bad - # # closed_at 1.day.from_now - # # - # # # good - # # closed_at { 1.day.from_now } - # # - # # # bad - # # count 1 - # # - # # # good - # # count { 1 } - # # - # class AttributeDefinedStatically < ::RuboCop::Cop::Base; end - AttributeDefinedStatically = - ::RuboCop::Cop::FactoryBot::AttributeDefinedStatically - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb b/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb deleted file mode 100644 index 59089974e..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Use a consistent style for parentheses in factory bot calls. - # # - # # @example - # # - # # # bad - # # create :user - # # build(:user) - # # create(:login) - # # create :login - # # - # # @example `EnforcedStyle: require_parentheses` (default) - # # - # # # good - # # create(:user) - # # create(:user) - # # create(:login) - # # build(:login) - # # - # # @example `EnforcedStyle: omit_parentheses` - # # - # # # good - # # create :user - # # build :user - # # create :login - # # create :login - # # - # # # also good - # # # when method name and first argument are not on same line - # # create( - # # :user - # # ) - # # build( - # # :user, - # # name: 'foo' - # # ) - # # - # class ConsistentParenthesesStyle < ::RuboCop::Cop::Base; end - ConsistentParenthesesStyle = - ::RuboCop::Cop::FactoryBot::ConsistentParenthesesStyle - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/create_list.rb b/lib/rubocop/cop/rspec/factory_bot/create_list.rb deleted file mode 100644 index 58e5c577d..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/create_list.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Checks for create_list usage. - # # - # # This cop can be configured using the `EnforcedStyle` option - # # - # # @example `EnforcedStyle: create_list` (default) - # # # bad - # # 3.times { create :user } - # # - # # # good - # # create_list :user, 3 - # # - # # # bad - # # 3.times { create :user, age: 18 } - # # - # # # good - index is used to alter the created models attributes - # # 3.times { |n| create :user, age: n } - # # - # # # good - contains a method call, may return different values - # # 3.times { create :user, age: rand } - # # - # # @example `EnforcedStyle: n_times` - # # # bad - # # create_list :user, 3 - # # - # # # good - # # 3.times { create :user } - # # - # class CreateList < ::RuboCop::Cop::Base; end - CreateList = ::RuboCop::Cop::FactoryBot::CreateList - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb b/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb deleted file mode 100644 index cb0f5a970..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Use string value when setting the class attribute explicitly. - # # - # # This cop would promote faster tests by lazy-loading of - # # application files. Also, this could help you suppress potential - # # bugs in combination with external libraries by avoiding a preload - # # of application files from the factory files. - # # - # # @example - # # # bad - # # factory :foo, class: Foo do - # # end - # # - # # # good - # # factory :foo, class: 'Foo' do - # # end - # # - # class FactoryClassName < ::RuboCop::Cop::Base; end - FactoryClassName = ::RuboCop::Cop::FactoryBot::FactoryClassName - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb b/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb deleted file mode 100644 index c04ed4702..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Checks for name style for argument of FactoryBot::Syntax::Methods. - # # - # # @example EnforcedStyle: symbol (default) - # # # bad - # # create('user') - # # build "user", username: "NAME" - # # - # # # good - # # create(:user) - # # build :user, username: "NAME" - # # - # # @example EnforcedStyle: string - # # # bad - # # create(:user) - # # build :user, username: "NAME" - # # - # # # good - # # create('user') - # # build "user", username: "NAME" - # # - # class FactoryNameStyle < ::RuboCop::Cop::Base; end - FactoryNameStyle = ::RuboCop::Cop::FactoryBot::FactoryNameStyle - end - end - end -end diff --git a/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb b/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb deleted file mode 100644 index 05492740f..000000000 --- a/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module FactoryBot - # @!parse - # # Use shorthands from `FactoryBot::Syntax::Methods` in your specs. - # # - # # @safety - # # The autocorrection is marked as unsafe because the cop - # # cannot verify whether you already include - # # `FactoryBot::Syntax::Methods` in your test suite. - # # - # # If you're using Rails, add the following configuration to - # # `spec/support/factory_bot.rb` and be sure to require that file - # # in `rails_helper.rb`: - # # - # # [source,ruby] - # # ---- - # # RSpec.configure do |config| - # # config.include FactoryBot::Syntax::Methods - # # end - # # ---- - # # - # # If you're not using Rails: - # # - # # [source,ruby] - # # ---- - # # RSpec.configure do |config| - # # config.include FactoryBot::Syntax::Methods - # # - # # config.before(:suite) do - # # FactoryBot.find_definitions - # # end - # # end - # # ---- - # # - # # @example - # # # bad - # # FactoryBot.create(:bar) - # # FactoryBot.build(:bar) - # # FactoryBot.attributes_for(:bar) - # # - # # # good - # # create(:bar) - # # build(:bar) - # # attributes_for(:bar) - # # - # class SyntaxMethods < ::RuboCop::Cop::Base; end - SyntaxMethods = ::RuboCop::Cop::FactoryBot::SyntaxMethods - end - end - end -end diff --git a/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb b/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb deleted file mode 100644 index 528197a5b..000000000 --- a/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - AvoidSetupHook = ::RuboCop::Cop::RSpecRails::AvoidSetupHook - end - 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 deleted file mode 100644 index d94294081..000000000 --- a/lib/rubocop/cop/rspec/rails/have_http_status.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - HaveHttpStatus = ::RuboCop::Cop::RSpecRails::HaveHttpStatus - end - end - end -end diff --git a/lib/rubocop/cop/rspec/rails/http_status.rb b/lib/rubocop/cop/rspec/rails/http_status.rb deleted file mode 100644 index 37a4ab2b0..000000000 --- a/lib/rubocop/cop/rspec/rails/http_status.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - HttpStatus = ::RuboCop::Cop::RSpecRails::HttpStatus - end - 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 deleted file mode 100644 index d56f96387..000000000 --- a/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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 < RuboCop::Cop::RSpec::Base; end - InferredSpecType = ::RuboCop::Cop::RSpecRails::InferredSpecType - end - end - end -end diff --git a/lib/rubocop/cop/rspec/rails/minitest_assertions.rb b/lib/rubocop/cop/rspec/rails/minitest_assertions.rb deleted file mode 100644 index 3a9819cff..000000000 --- a/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - MinitestAssertions = ::RuboCop::Cop::RSpecRails::MinitestAssertions - 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 deleted file mode 100644 index 9a9b0b8ca..000000000 --- a/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - NegationBeValid = ::RuboCop::Cop::RSpecRails::NegationBeValid - end - end - end -end diff --git a/lib/rubocop/cop/rspec/rails/travel_around.rb b/lib/rubocop/cop/rspec/rails/travel_around.rb deleted file mode 100644 index 7ee68f847..000000000 --- a/lib/rubocop/cop/rspec/rails/travel_around.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - module Rails - # @!parse - # # 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; end - TravelAround = ::RuboCop::Cop::RSpecRails::TravelAround - end - end - end -end diff --git a/lib/rubocop/cop/rspec_cops.rb b/lib/rubocop/cop/rspec_cops.rb index 7af420e4e..d32136009 100644 --- a/lib/rubocop/cop/rspec_cops.rb +++ b/lib/rubocop/cop/rspec_cops.rb @@ -1,28 +1,6 @@ # 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/http_status' -require_relative 'rspec/rails/inferred_spec_type' -require_relative 'rspec/rails/minitest_assertions' -require_relative 'rspec/rails/negation_be_valid' -require_relative 'rspec/rails/travel_around' require_relative 'rspec/align_left_let_brace' require_relative 'rspec/align_right_let_brace' diff --git a/lib/rubocop/rspec/config_formatter.rb b/lib/rubocop/rspec/config_formatter.rb index 4e9566cee..9a06a7780 100644 --- a/lib/rubocop/rspec/config_formatter.rb +++ b/lib/rubocop/rspec/config_formatter.rb @@ -7,29 +7,7 @@ module RSpec # 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 - RSpec/Rails/AvoidSetupHook - RSpec/Rails/HaveHttpStatus - RSpec/Rails/HttpStatus - RSpec/Rails/InferredSpecType - RSpec/Rails/MinitestAssertions - RSpec/Rails/NegationBeValid - RSpec/Rails/TravelAround - ) + SUBDEPARTMENTS = %(RSpec/Capybara) AMENDMENTS = %(Metrics/BlockLength) COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/' @@ -51,7 +29,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/rubocop-rspec.gemspec b/rubocop-rspec.gemspec index 858afb1f0..1a3b64f94 100644 --- a/rubocop-rspec.gemspec +++ b/rubocop-rspec.gemspec @@ -38,7 +38,4 @@ Gem::Specification.new do |spec| } 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_rails', '~> 2.28' end diff --git a/spec/project/default_config_spec.rb b/spec/project/default_config_spec.rb index b45a416a5..a53b8cc66 100644 --- a/spec/project/default_config_spec.rb +++ b/spec/project/default_config_spec.rb @@ -8,15 +8,13 @@ let(:namespaces) do { 'rspec' => 'RSpec', - 'capybara' => 'RSpec/Capybara', - 'factory_bot' => 'RSpec/FactoryBot', - 'rails' => 'RSpec/Rails' + 'capybara' => 'RSpec/Capybara' } end let(:cop_names) do glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec', - '{,capybara,factory_bot,rails}', '*.rb') + '{,capybara}', '*.rb') cop_names = Pathname.glob(glob).map do |file| file_name = file.basename('.rb').to_s diff --git a/spec/rubocop/cli/autocorrect_spec.rb b/spec/rubocop/cli/autocorrect_spec.rb index 5cbf2a361..abcd75082 100644 --- a/spec/rubocop/cli/autocorrect_spec.rb +++ b/spec/rubocop/cli/autocorrect_spec.rb @@ -7,48 +7,6 @@ include_context 'when cli spec behavior' - context 'when corrects `RSpec/Capybara/CurrentPathExpectation` with ' \ - '`Style/TrailingCommaInArguments`' do - before do - RuboCop::ConfigLoader - .default_configuration - .for_all_cops['SuggestExtensions'] = false - - create_file('.rubocop.yml', <<~YAML) - Style/TrailingCommaInArguments: - EnforcedStyleForMultiline: 'comma' - YAML - - create_file('spec/example.rb', <<~RUBY) - expect(page.current_path).to eq( - some_path( - id: id - ) - ) - RUBY - end - - it 'rubocop terminates with a success' do - expect(cli.run(['-A', '--only', - 'RSpec/Capybara/CurrentPathExpectation,' \ - 'Style/TrailingCommaInArguments'])).to eq(0) - end - - it 'autocorrects be compatible with each other' do - cli.run(['-A', '--only', - 'RSpec/Capybara/CurrentPathExpectation,' \ - 'Style/TrailingCommaInArguments']) - - expect(File.read('spec/example.rb')).to eq(<<~RUBY) - expect(page).to have_current_path( - some_path( - id: id, - ), ignore_query: true - ) - RUBY - end - end - context 'when corrects `RSpec/AlignLeftLetBrace` and ' \ '`RSpec/AlignRightLetBrace` with `Layout/ExtraSpacing`' do before do diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index 474896e26..aa157fe08 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -12,90 +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 - %w[ - RuboCop::Cop::RSpec::Rails::AvoidSetupHook - RuboCop::Cop::RSpec::Rails::HaveHttpStatus - RuboCop::Cop::RSpec::Rails::HttpStatus - RuboCop::Cop::RSpec::Rails::InferredSpecType - RuboCop::Cop::RSpec::Rails::MinitestAssertions - RuboCop::Cop::RSpec::Rails::NegationBeValid - RuboCop::Cop::RSpec::Rails::TravelAround - ].each do |extracted_cop| - cop = Class.const_get(extracted_cop) - class << cop - def badge - RuboCop::Cop::Badge.for(name) - end - - def name - super.sub('::RSpecRails::', '::RSpec::Rails::') - end - - def department - :'RSpec/Rails' - 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[RSpec RSpec/Capybara] + ) + generator.call end desc 'Syntax check for the documentation comments'