Skip to content

Commit d9b3dab

Browse files
committed
fix: don't care about missing deltas
1 parent 9df327a commit d9b3dab

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/rubocop/cop/rspec_rails/minitest_assertions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,10 @@ class InDeltaAssertion < BasicAssertion
136136

137137
# @!method self.minitest_assertion(node)
138138
def_node_matcher 'self.minitest_assertion', <<~PATTERN # rubocop:disable InternalAffairs/NodeMatcherDirective
139-
(send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $!{sym str}? $_?)
139+
(send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $_? $_?)
140140
PATTERN
141141

142142
def self.match(expected, actual, delta, failure_message)
143-
return nil if delta.empty? && !failure_message.empty?
144-
145143
new(expected, actual, delta.first, failure_message.first)
146144
end
147145

spec/rubocop/cop/rspec_rails/minitest_assertions_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@
335335
RUBY
336336
end
337337

338+
it 'registers an offense when using `assert_in_delta` with ' \
339+
'a missing delta' do
340+
expect_offense(<<~RUBY)
341+
assert_in_delta a, b, "whoops, we forgot about the actual delta!"
342+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).to be_within("whoops, we forgot about the actual delta!").of(a)`.
343+
RUBY
344+
345+
expect_correction(<<~RUBY)
346+
expect(b).to be_within("whoops, we forgot about the actual delta!").of(a)
347+
RUBY
348+
end
349+
338350
it 'registers an offense when using `assert_in_delta` with ' \
339351
'multi-line arguments' do
340352
expect_offense(<<~RUBY)
@@ -384,12 +396,6 @@
384396
expect(b).not_to be_within(1).of(a)
385397
RUBY
386398
end
387-
388-
it 'does not register an offense when the delta is missing' do
389-
expect_no_offenses(<<~RUBY)
390-
assert_in_delta a, b, "whoops, we forgot about the actual delta!"
391-
RUBY
392-
end
393399
end
394400

395401
context 'with match assertions' do

0 commit comments

Comments
 (0)