Class: RuboCop::Cop::RSpec::SubjectStub
- Includes:
- RSpec::TopLevelDescribe
- 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.'
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
- #expectation?(node) ⇒ Boolean
-
#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::TopLevelDescribe
Methods inherited from Cop
Instance Method Details
#expectation?(node) ⇒ Boolean
73 74 75 76 77 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 73 def expectation?(node) return if all_matcher?(node) (node) end |
#message_expectation?(node, method_name) ⇒ Object
Match ‘allow` and `expect(…).to receive`
62 63 64 65 66 67 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 62 def_node_matcher :message_expectation?, <<-PATTERN { (send nil? :allow (send nil? %)) (send (send nil? :expect (send nil? %)) :to #expectation?) } PATTERN |
#on_block(node) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 79 def on_block(node) return unless example_group?(node) find_subject_stub(node) do |stub| add_offense(stub, location: :expression) end end |
#subject(node) {|Symbol| ... } ⇒ Object
Find a named or unnamed subject definition
41 42 43 44 45 46 |
# File 'lib/rubocop/cop/rspec/subject_stub.rb', line 41 def_node_matcher :subject, <<-PATTERN { (block (send nil? :subject (sym $_)) args ...) (block (send nil? $:subject) args ...) } PATTERN |