Sha256: 26946f5ac43982fadeff64c3bbaa12e56e367ab751ffe5b036784e82fb6b1199

Contents?: true

Size: 917 Bytes

Versions: 5

Compression:

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

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-rspec-1.12.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.11.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.10.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.9.1 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.9.0 lib/rubocop/cop/rspec/verified_doubles.rb