Sha256: 822fcab76d0ec6e84425440965f1cf486b8946c07bddc2ab59574a21e9f48cfc

Contents?: true

Size: 838 Bytes

Versions: 9

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Check that chains of messages are not being stubbed.
      #
      # @example
      #   # bad
      #   allow(foo).to receive_message_chain(:bar, :baz).and_return(42)
      #
      #   # better
      #   thing = Thing.new(baz: 42)
      #   allow(foo).to receive(:bar).and_return(thing)
      #
      class MessageChain < Base
        MSG = 'Avoid stubbing using `%<method>s`.'

        def_node_matcher :message_chain, <<-PATTERN
          (send _ {:receive_message_chain :stub_chain} ...)
        PATTERN

        def on_send(node)
          message_chain(node) do
            add_offense(
              node.loc.selector,
              message: format(MSG, method: node.method_name)
            )
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-2.0.0 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-2.0.0.pre lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/message_chain.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/message_chain.rb