Sha256: ae8c42e25d26d03802dd2513979eed2a5f83948774e8171f47e7e61efa8d23b7

Contents?: true

Size: 1007 Bytes

Versions: 53

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks for equality assertions with identical expressions on both sides.
      #
      # @example
      #   # bad
      #   expect(foo.bar).to eq(foo.bar)
      #   expect(foo.bar).to eql(foo.bar)
      #
      #   # good
      #   expect(foo.bar).to eq(2)
      #   expect(foo.bar).to eql(2)
      #
      class IdenticalEqualityAssertion < Base
        MSG = 'Identical expressions on both sides of the equality ' \
              'may indicate a flawed test.'
        RESTRICT_ON_SEND = %i[to].freeze

        # @!method equality_check?(node)
        def_node_matcher :equality_check?, <<~PATTERN
          (send (send nil? :expect $_) :to
            {(send nil? {:eql :eq :be} $_)
             (send (send nil? :be) :== $_)})
        PATTERN

        def on_send(node)
          equality_check?(node) do |left, right|
            add_offense(node) if left == right
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 51 versions & 7 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/identical_equality_assertion.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/identical_equality_assertion.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb