Class: RuboCop::Cop::RSpec::ImplicitSubject
- Extended by:
- AutoCorrector
- 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."
- RESTRICT_ON_SEND =
%i[is_expected should should_not].freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#implicit_subject?(node) ⇒ Object
37 38 39 |
# File 'lib/rubocop/cop/rspec/implicit_subject.rb', line 37 def_node_matcher :implicit_subject?, <<-PATTERN (send nil? {:should :should_not :is_expected} ...) PATTERN |
#on_send(node) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/rubocop/cop/rspec/implicit_subject.rb', line 41 def on_send(node) return unless implicit_subject?(node) return if valid_usage?(node) add_offense(node) do |corrector| autocorrect(corrector, node) end end |