Sha256: 40a375854559befa8242571ffd44a9668d5638176e1992372c0c4be13d439f48

Contents?: true

Size: 1015 Bytes

Versions: 15

Compression:

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

15 entries across 13 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/identical_equality_assertion.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/identical_equality_assertion.rb