Class: RuboCop::Cop::RSpec::ImplicitSubject
- Includes:
- ConfigurableEnforcedStyle
- Defined in:
- lib/rubocop/cop/rspec/implicit_subject.rb
Overview
Checks for usage of implicit subject (‘is_expected` / `should`).
This cop can be configured using the ‘EnforcedStyle` option
Constant Summary collapse
- MSG =
"Don't use implicit subject."
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/rspec/implicit_subject.rb', line 45 def autocorrect(node) replacement = 'expect(subject)' if node.method_name == :should replacement += '.to' elsif node.method_name == :should_not replacement += '.not_to' end ->(corrector) { corrector.replace(node.loc.selector, replacement) } end |
#on_send(node) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/rubocop/cop/rspec/implicit_subject.rb', line 38 def on_send(node) return unless implicit_subject?(node) return if valid_usage?(node) add_offense(node) end |