Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ RSpecRails:
- "**/spec/**/*"

RSpecRails/AvoidSetupHook:
Description: Checks that tests use RSpec `before` hook over Rails `setup` method.
Description: Prefer RSpec `before` hook over Rails `setup` method.
Copy link
Member

Choose a reason for hiding this comment

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

I’m uncertain if “prefer” is correct here. Two reasons off the top of my head:

  1. I recall that in the Ruby Style guide, editors avoid soft wording like “recommend”, “prefer” or “advise”, and use more insistent terms
  2. The “description” should answer the “what it does” question. With “prefer”, it answers to “what the code should adhere to?”

Please donn’t take this note as a request or call to action, I just spark a discussion, and would like to have more input.

A brief look at https://docs.rubocop.org/rubocop/1.81/cops_layout.html#layoutarrayalignment shows that cops do use “Checks if …”

Enabled: pending
VersionAdded: '2.4'
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/AvoidSetupHook

RSpecRails/HaveHttpStatus:
Description: Checks that tests use `have_http_status` instead of equality matchers.
Description: Prefer `have_http_status` over equality matchers.
Enabled: pending
ResponseMethods:
- response
Expand All @@ -24,7 +24,7 @@ RSpecRails/HaveHttpStatus:
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HaveHttpStatus

RSpecRails/HttpStatus:
Description: Enforces use of symbolic or numeric value to describe HTTP status.
Description: Enforce use of symbolic or numeric value to describe HTTP status.
Enabled: true
EnforcedStyle: symbolic
SupportedStyles:
Expand All @@ -36,13 +36,13 @@ RSpecRails/HttpStatus:
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatus

RSpecRails/HttpStatusNameConsistency:
Description: Enforces consistency by using the current HTTP status names.
Description: Enforce consistency by using the current HTTP status names.
Enabled: pending
VersionAdded: '2.32'
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/HttpStatusNameConsistency

RSpecRails/InferredSpecType:
Description: Identifies redundant spec type.
Description: Identify redundant spec type.
Enabled: pending
Safe: false
VersionAdded: '2.14'
Expand All @@ -65,13 +65,13 @@ RSpecRails/InferredSpecType:
views: view

RSpecRails/MinitestAssertions:
Description: Check if using Minitest-like matchers.
Description: Prefer RSpec/Rails-style matchers over Minitest-like matchers.
Enabled: pending
VersionAdded: '2.17'
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/MinitestAssertions

RSpecRails/NegationBeValid:
Description: Enforces use of `be_invalid` or `not_to` for negated be_valid.
Description: Enforce use of `be_invalid` or `not_to` for negated be_valid.
AutoCorrect: contextual
Safe: false
EnforcedStyle: not_to
Expand Down
43 changes: 19 additions & 24 deletions docs/modules/ROOT/pages/cops_rspecrails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
| -
|===

Checks that tests use RSpec `before` hook over Rails `setup` method.
Prefer RSpec `before` hook over Rails `setup` method.

[#examples-rspecrailsavoidsetuphook]
=== Examples
Expand Down Expand Up @@ -55,13 +55,13 @@ end
| 2.27
|===

Checks that tests use `have_http_status` instead of equality matchers.
Prefer `have_http_status` over equality matchers.

[#examples-rspecrailshavehttpstatus]
=== Examples

[#responsemethods_-__response__-_last_response__-_default_-rspecrailshavehttpstatus]
==== ResponseMethods: ['response', 'last_response'] (default)
[#_responsemethods_-__response__-_last_response___-_default_-rspecrailshavehttpstatus]
==== `ResponseMethods: ['response', 'last_response']` (default)

[source,ruby]
----
Expand All @@ -74,8 +74,8 @@ expect(response).to have_http_status(200)
expect(last_response).to have_http_status(200)
----

[#responsemethods_-__foo_response__-rspecrailshavehttpstatus]
==== ResponseMethods: ['foo_response']
[#_responsemethods_-__foo_response___-rspecrailshavehttpstatus]
==== `ResponseMethods: ['foo_response']`

[source,ruby]
----
Expand Down Expand Up @@ -119,7 +119,7 @@ expect(last_response).to have_http_status(200)
| 2.20
|===

Enforces use of symbolic or numeric value to describe HTTP status.
Enforce 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
Expand Down Expand Up @@ -224,7 +224,7 @@ it { is_expected.to have_http_status :ok }
| -
|===

Enforces consistency by using the current HTTP status names.
Enforce consistency by using the current HTTP status names.

[#examples-rspecrailshttpstatusnameconsistency]
=== Examples
Expand Down Expand Up @@ -256,7 +256,7 @@ it { is_expected.to have_http_status :unprocessable_content }
| -
|===

Identifies redundant spec type.
Identify redundant spec type.

After setting up rspec-rails, you will have enabled
`config.infer_spec_type_from_file_location!` by default in
Expand Down Expand Up @@ -290,16 +290,11 @@ RSpec.describe User, type: :common do
end
----

[#_inferences_-configuration-rspecrailsinferredspectype]
==== `Inferences` configuration
[#_inferences_-_services_-service__-rspecrailsinferredspectype]
==== `Inferences: {services: service}`

[source,ruby]
----
# .rubocop.yml
# RSpecRails/InferredSpecType:
# Inferences:
# services: service

# bad
# spec/services/user_spec.rb
RSpec.describe User, type: :service do
Expand Down Expand Up @@ -345,10 +340,10 @@ end
| -
|===

Check if using Minitest-like matchers.
Prefer RSpec/Rails-style matchers over Minitest-like matchers.

Check the use of minitest-like matchers
starting with `assert_` or `refute_`.
Detect the use of Minitest-like matchers
(those starting with `assert_` or `refute_`).

[#examples-rspecrailsminitestassertions]
=== Examples
Expand Down Expand Up @@ -396,7 +391,7 @@ expect(response).to have_http_status(:ok)
| 2.29
|===

Enforces use of `be_invalid` or `not_to` for negated be_valid.
Enforce use of `be_invalid` or `not_to` for negated be_valid.

[#safety-rspecrailsnegationbevalid]
=== Safety
Expand All @@ -407,8 +402,8 @@ the test target is an instance of `ActiveModel::Validations``.
[#examples-rspecrailsnegationbevalid]
=== Examples

[#enforcedstyle_-not_to-_default_-rspecrailsnegationbevalid]
==== EnforcedStyle: not_to (default)
[#_enforcedstyle_-not_to_-_default_-rspecrailsnegationbevalid]
==== `EnforcedStyle: not_to` (default)

[source,ruby]
----
Expand All @@ -422,8 +417,8 @@ expect(foo).not_to be_valid
expect(foo).to be_invalid.and be_odd
----

[#enforcedstyle_-be_invalid-rspecrailsnegationbevalid]
==== EnforcedStyle: be_invalid
[#_enforcedstyle_-be_invalid_-rspecrailsnegationbevalid]
==== `EnforcedStyle: be_invalid`

[source,ruby]
----
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec_rails/avoid_setup_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Cop
module RSpecRails
# Checks that tests use RSpec `before` hook over Rails `setup` method.
# Prefer RSpec `before` hook over Rails `setup` method.
#
# @example
# # bad
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec_rails/have_http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
module RuboCop
module Cop
module RSpecRails
# Checks that tests use `have_http_status` instead of equality matchers.
# Prefer `have_http_status` over equality matchers.
#
# @example ResponseMethods: ['response', 'last_response'] (default)
# @example `ResponseMethods: ['response', 'last_response']` (default)
# # bad
# expect(response.status).to be(200)
# expect(last_response.code).to eq("200")
Expand All @@ -14,7 +14,7 @@ module RSpecRails
# expect(response).to have_http_status(200)
# expect(last_response).to have_http_status(200)
#
# @example ResponseMethods: ['foo_response']
# @example `ResponseMethods: ['foo_response']`
# # bad
# expect(foo_response.status).to be(200)
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec_rails/http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module RuboCop
module Cop
module RSpecRails
# Enforces use of symbolic or numeric value to describe HTTP status.
# Enforce 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Cop
module RSpecRails
# Enforces consistency by using the current HTTP status names.
# Enforce consistency by using the current HTTP status names.
#
# @example
#
Expand Down
9 changes: 2 additions & 7 deletions lib/rubocop/cop/rspec_rails/inferred_spec_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Cop
module RSpecRails
# Identifies redundant spec type.
# Identify redundant spec type.
#
# After setting up rspec-rails, you will have enabled
# `config.infer_spec_type_from_file_location!` by default in
Expand All @@ -30,12 +30,7 @@ module RSpecRails
# RSpec.describe User, type: :common do
# end
#
# @example `Inferences` configuration
# # .rubocop.yml
# # RSpecRails/InferredSpecType:
# # Inferences:
# # services: service
#
# @example `Inferences: {services: service}`
# # bad
# # spec/services/user_spec.rb
# RSpec.describe User, type: :service do
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec_rails/minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
module RuboCop
module Cop
module RSpecRails
# Check if using Minitest-like matchers.
# Prefer RSpec/Rails-style matchers over Minitest-like matchers.
#
# Check the use of minitest-like matchers
# starting with `assert_` or `refute_`.
# Detect the use of Minitest-like matchers
# (those starting with `assert_` or `refute_`).
#
# @example
# # bad
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec_rails/negation_be_valid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module RuboCop
module Cop
module RSpecRails
# Enforces use of `be_invalid` or `not_to` for negated be_valid.
# Enforce 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)
# @example `EnforcedStyle: not_to` (default)
# # bad
# expect(foo).to be_invalid
#
Expand All @@ -19,7 +19,7 @@ module RSpecRails
# # good (with method chain)
# expect(foo).to be_invalid.and be_odd
#
# @example EnforcedStyle: be_invalid
# @example `EnforcedStyle: be_invalid`
# # bad
# expect(foo).not_to be_valid
#
Expand Down