Class: RuboCop::Cop::RSpec::StubbedMock
- Defined in:
- lib/rubocop/cop/rspec/stubbed_mock.rb
Overview
Checks that message expectations do not have a configured response.
Constant Summary collapse
- MSG =
'Prefer `%<replacement>s` over `%<method_name>s` when ' \ 'configuring a response.'
Instance Method Summary collapse
-
#expectation(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match expectation.
-
#matcher_with_blockpass(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response in block-pass.
-
#matcher_with_configured_response(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response.
-
#matcher_with_hash(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response defined as a hash.
-
#matcher_with_return_block(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a return block.
-
#message_expectation?(node) ⇒ Array<RuboCop::AST::Node>
Match message expectation matcher.
- #on_send(node) ⇒ Object
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#expectation(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match expectation
61 62 63 64 65 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 61 def_node_matcher :expectation, <<~PATTERN (send $(send nil? $#Expectations.all ...) :to $_) PATTERN |
#matcher_with_blockpass(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response in block-pass
129 130 131 132 133 134 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 129 def_node_matcher :matcher_with_blockpass, <<~PATTERN { (send nil? { :receive :receive_message_chain } ... block_pass) # receive(:foo, &canned) (send (send nil? :receive ...) :with ... block_pass) # receive(:foo).with('foo', &canned) } PATTERN |
#matcher_with_configured_response(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response
81 82 83 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 81 def_node_matcher :matcher_with_configured_response, <<~PATTERN (send #message_expectation? #configured_response? _) PATTERN |
#matcher_with_hash(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a configured response defined as a hash
108 109 110 111 112 113 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 108 def_node_matcher :matcher_with_hash, <<~PATTERN { (send nil? :receive_messages hash) # receive_messages(foo: 'bar', baz: 'qux') (send nil? :receive_message_chain ... hash) # receive_message_chain(:foo, bar: 'baz') } PATTERN |
#matcher_with_return_block(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match matcher with a return block
93 94 95 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 93 def_node_matcher :matcher_with_return_block, <<~PATTERN (block #message_expectation? args _) # receive(:foo) { 'bar' } PATTERN |
#message_expectation?(node) ⇒ Array<RuboCop::AST::Node>
Match message expectation matcher
35 36 37 38 39 40 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 35 def_node_matcher :message_expectation?, <<-PATTERN { (send nil? { :receive :receive_message_chain } ...) # receive(:foo) (send (send nil? :receive ...) :with ...) # receive(:foo).with('bar') } PATTERN |
#on_send(node) ⇒ Object
136 137 138 |
# File 'lib/rubocop/cop/rspec/stubbed_mock.rb', line 136 def on_send(node) expectation(node, &method(:on_expectation)) end |