Class: RuboCop::Cop::RSpec::SubjectStub
- Includes:
- TopLevelGroup
- Defined in:
- lib/rubocop/cop/rspec/subject_stub.rb
Overview
Checks for stubbed test subjects.
Constant Summary collapse
- MSG =
'Do not stub methods of the object under test.'
Instance Method Summary collapse
-
#message_expectation?(node, method_name) ⇒ Object
Match ‘allow` and `expect(…).to receive`.
- #on_top_level_group(node) ⇒ Object
-
#subject(node) {|Symbol| ... } ⇒ Object
Find a named or unnamed subject definition.
Methods included from TopLevelGroup
#on_new_investigation, #top_level_groups
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#message_expectation?(node, method_name) ⇒ Object
Match ‘allow` and `expect(…).to receive`
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 73 def_node_matcher :message_expectation?, <<-PATTERN (send { (send nil? { :expect :allow } (send nil? {% :subject})) (send nil? :is_expected) } #Runners.all #message_expectation_matcher? ) PATTERN |
#on_top_level_group(node) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 90 def on_top_level_group(node) @explicit_subjects = find_all_explicit_subjects(node) find_subject_expectations(node) do |stub| add_offense(stub) end end |
#subject(node) {|Symbol| ... } ⇒ Object
Find a named or unnamed subject definition
55 56 57 58 59 60 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 55 def_node_matcher :subject, <<-PATTERN (block (send nil? {:subject (sym $_) | $:subject} ) args ...) PATTERN |