Sha256: 4b7640e077496a7749acdfdbd2325d62e2988547c850ba662c63ea4d8ace6a9f
Contents?: true
Size: 1.14 KB
Versions: 30
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module RuboCop module Cop # Common functionality for `AssertInDelta` and `RefuteInDelta` cops. # @api private module InDeltaMixin MSG = 'Prefer using `%<good_method>s`.' def on_send(node) equal_floats_call(node) do |expected, actual, message| message = message.first good_method = build_good_method(expected, actual, message) if expected.float_type? || actual.float_type? message = format(MSG, good_method: good_method) add_offense(node, message: message) do |corrector| corrector.replace(node, good_method) end end end end private def build_good_method(expected, actual, message) if message "#{assertion_method}_in_delta(#{expected.source}, #{actual.source}, 0.001, #{message.source})" else "#{assertion_method}_in_delta(#{expected.source}, #{actual.source})" end end def assertion_method class_name = self.class.name.split('::').last class_name[/\A[[:upper:]][[:lower:]]+/].downcase end end end end
Version data entries
30 entries across 30 versions & 1 rubygems