Sha256: 2705914a16bb26802ab9aea018ac6d9bce8ce2b864829028536cbd237de49b8a

Contents?: true

Size: 925 Bytes

Versions: 7

Compression:

Stored size: 925 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)
          unverified_double(node) do |name|
            return if name.sym_type? && cop_config['IgnoreSymbolicNames']

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.22.2 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.22.1 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.22.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.21.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.20.1 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.20.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.19.0 lib/rubocop/cop/rspec/verified_doubles.rb