# frozen_string_literal: true
require 'minitest/autorun'
# test
class AssertInDeltaTest < Minitest::Test
def test_assert_in_delta_cop
refute_equal(4.2, 420_001 / 100_000.0)
end
end
Fails because the default delta value for refute_in_delta is 0.001. As Rubocop can never know the user's intended delta value this cop is not safe for autocorrect.
Don't know whether you'd consider Minitest/RefuteInDelta unsafe also, as if you replace the assertion in the above example with assert_equal, autocorrect turns a failing test into one that passes..
I'd also suggest the suggestion text for bothcops use the good code examples where an explicit delta value is provided.
.rubocop.yml
test/test_minitest_assert_in_delta.rb
$ ruby test/test_minitest_assert_in_delta.rb
=> pass$ rubocop
$ rubocop -a
=> autocorrected$ ruby test/test_minitest_assert_in_delta.rb
=> failFails because the default delta value for
refute_in_delta
is 0.001. As Rubocop can never know the user's intended delta value this cop is not safe for autocorrect.Don't know whether you'd consider Minitest/RefuteInDelta unsafe also, as if you replace the assertion in the above example with
assert_equal
, autocorrect turns a failing test into one that passes..I'd also suggest the suggestion text for both cops use the good code examples where an explicit delta value is provided.