Sha256: b23dfd1c1c07c8baf7bc143ade7b47a1cc5ce5894504d7106e70bdf7200c09f8

Contents?: true

Size: 789 Bytes

Versions: 32

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Enforces the test to use `assert_in_delta`
      # instead of using `assert_equal` to compare floats.
      #
      # @example
      #   # bad
      #   assert_equal(0.2, actual)
      #   assert_equal(0.2, actual, 'message')
      #
      #   # good
      #   assert_in_delta(0.2, actual)
      #   assert_in_delta(0.2, actual, 0.001, 'message')
      #
      class AssertInDelta < Base
        include InDeltaMixin
        extend AutoCorrector

        RESTRICT_ON_SEND = %i[assert_equal].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend

        def_node_matcher :equal_floats_call, <<~PATTERN
          (send nil? :assert_equal $_ $_ $...)
        PATTERN
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rubocop-minitest-0.36.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.35.1 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.35.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.5 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.4 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.3 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.2 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.1 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.34.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.33.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.32.2 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.32.1 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.32.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.31.1 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.31.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.30.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.29.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.28.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.27.0 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.26.1 lib/rubocop/cop/minitest/assert_in_delta.rb