Skip to content

Commit

Permalink
Add missing SkipBlocks option documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Aug 9, 2019
1 parent 6a1336a commit e6c6aaa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
24 changes: 23 additions & 1 deletion lib/rubocop/cop/rspec/described_class.rb
Expand Up @@ -8,7 +8,8 @@ module RSpec
# If the first argument of describe is a class, the class is exposed to
# each example via described_class.
#
# This cop can be configured using the `EnforcedStyle` option
# This cop can be configured using the `EnforcedStyle` and `SkipBlocks`
# options.
#
# @example `EnforcedStyle: described_class`
# # bad
Expand All @@ -32,6 +33,27 @@ module RSpec
# subject { MyClass.do_something }
# end
#
# There's a known caveat with rspec-rails's `controller` helper that
# runs its block in a different context, and `described_class` is not
# available to it. `SkipBlocks` option excludes detection in all
# non-RSpec related blocks.
#
# To narrow down this setting to only a specific directory, it is
# possible to use an overriding configuration file local to that
# directory.
#
# @example `SkipBlocks: true`
# # spec/controllers/.rubocop.yml
# # RSpec/DescribedClass:
# # SkipBlocks: true
#
# # acceptable
# describe MyConcern do
# controller(ApplicationController) do
# include MyConcern
# end
# end
#
class DescribedClass < Cop
include ConfigurableEnforcedStyle

Expand Down
26 changes: 25 additions & 1 deletion manual/cops_rspec.md
Expand Up @@ -369,7 +369,17 @@ Checks that tests use `described_class`.
If the first argument of describe is a class, the class is exposed to
each example via described_class.

This cop can be configured using the `EnforcedStyle` option
This cop can be configured using the `EnforcedStyle` and `SkipBlocks`
options.

There's a known caveat with rspec-rails's `controller` helper that
runs its block in a different context, and `described_class` is not
available to it. `SkipBlocks` option excludes detection in all
non-RSpec related blocks.

To narrow down this setting to only a specific directory, it is
possible to use an overriding configuration file local to that
directory.

### Examples

Expand Down Expand Up @@ -399,6 +409,20 @@ describe MyClass do
subject { MyClass.do_something }
end
```
#### `SkipBlocks: true`

```ruby
# spec/controllers/.rubocop.yml
# RSpec/DescribedClass:
# SkipBlocks: true

# acceptable
describe MyConcern do
controller(ApplicationController) do
include MyConcern
end
end
```

### Configurable attributes

Expand Down

0 comments on commit e6c6aaa

Please sign in to comment.