Sha256: d8b6949ad94b1e0a86aa12af46d031980d321f7e2b16767a1cd3fe8b5067fd87

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 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
        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

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-rspec-1.6.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.5.3 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.5.2 lib/rubocop/cop/rspec/verified_doubles.rb