Skip to content

Commit

Permalink
fix: don't care about missing deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jan 30, 2024
1 parent d706315 commit c566bb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/rubocop/cop/rspec/rails/minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ class InDeltaAssertion < BasicAssertion
].freeze

NODE_MATCHER_PATTERN = <<~PATTERN
(send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $!{sym str}? $_?)
(send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $_? $_?)
PATTERN

def self.match(expected, actual, delta, failure_message)
return nil if delta.empty? && !failure_message.empty?

new(expected, actual, delta.first, failure_message.first)
end

Expand Down
18 changes: 12 additions & 6 deletions spec/rubocop/cop/rspec/rails/minitest_assertions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@
RUBY
end

it 'registers an offense when using `assert_in_delta` with ' \
'a missing delta' do
expect_offense(<<~RUBY)
assert_in_delta a, b, "whoops, we forgot about the actual delta!"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).to be_within("whoops, we forgot about the actual delta!").of(a)`.
RUBY

expect_correction(<<~RUBY)
expect(b).to be_within("whoops, we forgot about the actual delta!").of(a)
RUBY
end

it 'registers an offense when using `assert_in_delta` with ' \
'multi-line arguments' do
expect_offense(<<~RUBY)
Expand Down Expand Up @@ -384,12 +396,6 @@
expect(b).not_to be_within(1).of(a)
RUBY
end

it 'does not register an offense when the delta is missing' do
expect_no_offenses(<<~RUBY)
assert_in_delta a, b, "whoops, we forgot about the actual delta!"
RUBY
end
end

context 'with match assertions' do
Expand Down

0 comments on commit c566bb2

Please sign in to comment.