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
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb