Sha256: 0002bfa6967b50dd4df3f8c317868ae55c46efcfa58c36e16f7cc1a9e8e48575

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

module RuboCop
  module Cop
    module RSpec
      # Prefer `not_to receive(...)` over `receive(...).never`.
      #
      # @example
      #
      #     # bad
      #     expect(foo).to receive(:bar).never
      #
      #     # good
      #     expect(foo).not_to receive(:bar)
      #
      class ReceiveNever < Cop
        include RangeHelp

        MSG = 'Use `not_to receive` instead of `never`.'.freeze

        def_node_search :method_on_stub?, '(send nil? :receive ...)'

        def on_send(node)
          return unless node.method_name == :never && method_on_stub?(node)

          add_offense(
            node,
            location: :selector
          )
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.replace(node.parent.loc.selector, 'not_to')
            range = range_between(
              node.loc.dot.begin_pos,
              node.loc.selector.end_pos
            )
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.31.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.30.1 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.30.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.29.1 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.29.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.28.0 lib/rubocop/cop/rspec/receive_never.rb