Sha256: 885e8f5ee59098df36f3d1c48fac3fa2a623a83d6a2372bb57b493736d674e62

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

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
      #   let(:foo) do
      #     double(method_name: 'returned value')
      #   end
      #
      #   # bad
      #   let(:foo) do
      #     double("ClassName", method_name: 'returned value')
      #   end
      #
      #   # good
      #   let(:foo) do
      #     instance_double("ClassName", method_name: 'returned value')
      #   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

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-rspec-1.29.1 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.29.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.28.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.27.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.26.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.25.1 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.25.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.24.0 lib/rubocop/cop/rspec/verified_doubles.rb
rubocop-rspec-1.23.0 lib/rubocop/cop/rspec/verified_doubles.rb