- Extended by:
- Defined in:
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` 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.
Constant Summary collapse
- DESCRIBED_CLASS =
- MSG =
'Use `%<replacement>s` instead of `%<src>s`.'
Instance Method Summary collapse
Methods inherited from
Methods included from
Instance Method Details
#on_block(node) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93
# File 'lib/rubocop/cop/rspec/described_class.rb', line 80 def on_block(node) # In case the explicit style is used, we need to remember what's # being described. @described_class, body = described_constant(node) return unless body find_usage(body) do |match| msg = (match.const_name) add_offense(match, message: msg) do |corrector| autocorrect(corrector, match) end end end