Class: RuboCop::Cop::RSpec::SubjectStub
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::RSpec::SubjectStub
- Defined in:
- lib/rubocop/cop/rspec/subject_stub.rb
Overview
Checks for stubbed test subjects.
Constant Summary collapse
- MSG =
'Do not stub your test subject.'.freeze
Constants included from RSpec::SpecOnly
RSpec::SpecOnly::DEFAULT_CONFIGURATION
Constants included from RSpec::Language
Instance Method Summary collapse
-
#message_expectation?(node, method_name) ⇒ Object
Match ‘allow` and `expect(…).to receive`.
- #on_block(node) ⇒ Object
-
#subject(node) {|Symbol| ... } ⇒ Object
Find a named or unnamed subject definition.
Methods included from RSpec::SpecOnly
Methods included from RSpec::TopLevelDescribe
Instance Method Details
#message_expectation?(node, method_name) ⇒ Object
Match ‘allow` and `expect(…).to receive`
61 62 63 64 65 66 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 61 def_node_matcher :message_expectation?, <<-PATTERN { (send nil :allow (send nil %)) (send (send nil :expect (send nil %)) :to #receive_message?) } PATTERN |
#on_block(node) ⇒ Object
70 71 72 73 74 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 70 def on_block(node) return unless example_group?(node) find_subject_stub(node) { |stub| add_offense(stub, :expression) } end |
#subject(node) {|Symbol| ... } ⇒ Object
Find a named or unnamed subject definition
44 45 46 47 48 49 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 44 def_node_matcher :subject, <<-PATTERN { (block (send nil :subject (sym $_)) args ...) (block (send nil $:subject) args ...) } PATTERN |