Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minitest/RefuteEmpty mangles File.empty? #150

Closed
go2null opened this issue Oct 21, 2021 · 1 comment · Fixed by #151
Closed

Minitest/RefuteEmpty mangles File.empty? #150

go2null opened this issue Oct 21, 2021 · 1 comment · Fixed by #151
Labels
bug Something isn't working

Comments

@go2null
Copy link

go2null commented Oct 21, 2021

RuboCop::Minitest/RefuteEmpty does not correctly handle File.empty?.

Expected behavior

RuboCop Minitest should not change the statement.

Actual behavior

RubuCop Minitest changes the code to be non-functioning

- refute File.empty?(@path)
+ refute_empty(File, @path)

Steps to reproduce the problem

  1. create the following test file
# frozen_string_literal: true

require_relative 'test_helper'

class RubocopMinitestAssertEmpty < Minitest::Test
  def test_that_file_is_not_empty
    refute File.empty?(__FILE__)
  end
end
  1. verify that it works
$ bundle exec ruby test/rubocop_minitest_assert_empty_bug.rb
Run options: --seed 20479

# Running:

.

Fabulous run in 0.009087s, 110.0522 runs/s, 110.0522 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  1. run RuboCop Minitest
$ rubocop --auto-correct

test/rubocop_minitest_assert_empty_bug.rb:7:5: C: [Corrected] Minitest/RefuteEmpty: Prefer using refute_empty(File, __FILE__) over refute(File.empty?(__FILE__)).
    refute File.empty?(__FILE__)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1. verify change made
# frozen_string_literal: true

require_relative 'test_helper'

class RubocopMinitestAssertEmpty < Minitest::Test
  def test_that_file_is_not_empty
    refute_empty File, __FILE__
  end
end
  1. try running test
$ bundle exec ruby test/rubocop_minitest_assert_empty_bug.rb
Run options: --seed 18518

# Running:

E

Fabulous run in 0.001397s, 715.8196 runs/s, 715.8196 assertions/s.

  1) Error:
RubocopMinitestAssertEmpty#test_that_file_is_not_empty:
ArgumentError: wrong number of arguments (given 0, expected 1)
    test/rubocop_minitest_assert_empty_bug.rb:7:in `test_that_file_is_not_empty'

1 runs, 1 assertions, 0 failures, 1 errors, 0 skips

RuboCop version

$ bundle exec rubocop -V
1.22.1 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 2.7.2 x86_64-msys)
  - rubocop-minitest 0.15.2
  - rubocop-rake 0.6.0
@andyw8
Copy link
Contributor

andyw8 commented Oct 21, 2021

FYI @abhaynikam (#20)

@koic koic added the bug Something isn't working label Oct 22, 2021
koic added a commit to koic/rubocop-minitest that referenced this issue Oct 22, 2021
… `RefuteEmpty`

Fixes rubocop#150.

This PR fixes a false positive for `Minitest/AssertEmpty` and `RefuteEmpty` cops
when using `empty` method with any arguments.
@koic koic closed this as completed in #151 Nov 5, 2021
koic added a commit that referenced this issue Nov 5, 2021
…_and_refute_empty

[Fix #150] Fix a false positive for `Minitest/AssertEmpty` and `RefuteEmpty`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants