Sha256: 1759e20f9198ca8b92ef4e657334e850d4671d53eee3b735cfb471a6e8a591ff

Contents?: true

Size: 712 Bytes

Versions: 2

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # This cop 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 < Cop
        include InDeltaMixin

        RESTRICT_ON_SEND = %i[assert_equal].freeze

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-minitest-0.11.1 lib/rubocop/cop/minitest/assert_in_delta.rb
rubocop-minitest-0.11.0 lib/rubocop/cop/minitest/assert_in_delta.rb