Sha256: 3742852bd65dde6e0c96b6a989d0626010e343c2eeb9169c3f79656b5313a917

Contents?: true

Size: 970 Bytes

Versions: 12

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

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
        MSG = 'Use `not_to receive` instead of `never`.'

        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 = node.loc.dot.with(end_pos: node.loc.selector.end_pos)
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubocop-rspec-1.41.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.40.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.39.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.38.1 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.38.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.37.1 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.37.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.36.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.35.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.34.1 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.34.0 lib/rubocop/cop/rspec/receive_never.rb
rubocop-rspec-1.33.0 lib/rubocop/cop/rspec/receive_never.rb