Class: RuboCop::Cop::RSpecRails::MinitestAssertions::InDeltaAssertion

Inherits:
BasicAssertion
  • Object
show all
Defined in:
lib/rubocop/cop/rspec_rails/minitest_assertions.rb

Overview

:nodoc:

Constant Summary collapse

MATCHERS =
%i[
  assert_in_delta
  assert_not_in_delta
  refute_in_delta
].freeze

Instance Attribute Summary

Attributes inherited from BasicAssertion

#actual, #expected, #failure_message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicAssertion

#negated?, #replaced

Constructor Details

#initialize(expected, actual, delta, fail_message) ⇒ InDeltaAssertion

Returns a new instance of InDeltaAssertion.



174
175
176
177
178
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 174

def initialize(expected, actual, delta, fail_message)
  super(expected, actual, fail_message)

  @delta = delta&.source || '0.001'
end

Class Method Details

.match(expected, actual, delta, failure_message) ⇒ Object



170
171
172
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 170

def self.match(expected, actual, delta, failure_message)
  new(expected, actual, delta.first, failure_message.first)
end

.minitest_assertion(node) ⇒ Object



166
167
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 166

def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective
(send nil? {:assert_in_delta :assert_not_in_d

Instance Method Details

#assertionObject



180
181
182
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 180

def assertion
  "be_within(#{@delta}).of(#{expected})"
end