Sha256: 1c90d2499cc6fab1a973ab60de767cd00f8b1abb254d13f07c1d9714265bd214

Contents?: true

Size: 959 Bytes

Versions: 2

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Prefer using verifying doubles over normal doubles.
      #
      # @see https://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles
      #
      # @example
      #   # bad
      #   it '...' do
      #     widget = double("Widget")
      #   end
      #
      #   # good
      #   it '...' do
      #     widget = instance_double("Widget")
      #   end
      class VerifiedDoubles < Cop
        include RuboCop::RSpec::SpecOnly

        MSG = 'Prefer using verifying doubles over normal doubles.'.freeze

        def_node_matcher :unverified_double, <<-PATTERN
          {(send nil {:double :spy} $_ ...) }
        PATTERN

        def on_send(node)
          return unless (name = unverified_double(node))
          return if name.type.equal?(:sym) && cop_config['IgnoreSymbolicNames']

          add_offense(node, :expression)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.8.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.7.0 lib/rubocop/cop/rspec/verified_doubles.rb