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/GlobalExpectations cop does not find offenses for must_be_nil and wont_be_nil expectations #75

Closed
yahonda opened this issue Apr 12, 2020 · 1 comment · Fixed by #76
Labels
bug Something isn't working

Comments

@yahonda
Copy link
Contributor

yahonda commented Apr 12, 2020

Expected behavior

Minitest/GlobalExpectations cop does not find offenses for wont_be_nil and must_be_nil as implemented at https://github.com/rubocop-hq/rubocop-minitest/blob/b6df77ea23fc633fb5fcdd6230101d5e1464b943/lib/rubocop/cop/minitest/global_expectations.rb#L25 and https://github.com/rubocop-hq/rubocop-minitest/blob/b6df77ea23fc633fb5fcdd6230101d5e1464b943/lib/rubocop/cop/minitest/global_expectations.rb#L28

Actual behavior

Minitest/GlobalExpectations finds offenses for and must_be_nil and wont_be_nil.

Steps to reproduce the problem

  • Create a script file rep.rb to reproduce
# frozen_string_literal: true

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
  gem 'minitest'
end

# Avoid `Style/Documentation: Missing top-level class documentation comment.`
class Greeting
  def say_hello
    'Hello, World!'
  end

  def say_nothing; end
end

require 'minitest/autorun'
describe Greeting do
  before do
    @foo = Greeting.new
  end

  it 'must say nothing must be nil' do
    # Bad and offense is NOT found by RuboCop
    @foo.say_nothing.must_be_nil
  end
  it 'must say hello wont be nil' do
    # Bad and offense is NOT found by RuboCop
    @foo.say_hello.wont_be_nil
  end
  it 'must say hello world with a warning' do
    # Bad and offense is found by RuboCop
    # It just proves RuboCop Minitest is working.
    @foo.say_hello.must_equal 'Hello, World!'
  end
end
  • Execute rep.rb and shows 3 deprecated warnings as expected
% ruby rep.rb
Fetching gem metadata from https://rubygems.org/..................
Resolving dependencies...
Using bundler 2.1.4
Using minitest 5.14.0
Run options: --seed 34712

# Running:

DEPRECATED: global use of must_be_nil from rep.rb:28. Use _(obj).must_be_nil instead. This will fail in Minitest 6.
.DEPRECATED: global use of wont_be_nil from rep.rb:32. Use _(obj).wont_be_nil instead. This will fail in Minitest 6.
.DEPRECATED: global use of must_equal from rep.rb:37. Use _(obj).must_equal instead. This will fail in Minitest 6.
.

Finished in 0.000850s, 3529.4118 runs/s, 3529.4118 assertions/s.

3 runs, 3 assertions, 0 failures, 0 errors, 0 skips
%
  • Run RuboCop Minitest to find these 3 offenses then only 1 offense for must_equal is found. This one just proves RuboCop minitest is working.
% rubocop --require rubocop-minitest --only Minitest/GlobalExpectations                                                                                                                                                     master
Inspecting 1 file
C

Offenses:

rep.rb:37:5: C: Minitest/GlobalExpectations: Use _(@foo.say_hello) instead.
    @foo.say_hello.must_equal 'Hello, World!'
    ^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
%

RuboCop version

% rubocop -V
0.81.0 (using Parser 2.7.1.0, running on ruby 2.7.1 x86_64-darwin19)
@koic koic added the bug Something isn't working label Apr 12, 2020
koic added a commit to koic/rubocop-minitest that referenced this issue Apr 12, 2020
Fixes rubocop#75

This PR fixes a false negative for `Minitest/GlobalExpectations`
when using global expectation methods with no arguemnts.
koic added a commit to koic/rubocop-minitest that referenced this issue Apr 12, 2020
Fixes rubocop#75

This PR fixes a false negative for `Minitest/GlobalExpectations`
when using global expectation methods with no arguments.
koic added a commit to koic/rubocop-minitest that referenced this issue Apr 12, 2020
Fixes rubocop#75.

This PR fixes a false negative for `Minitest/GlobalExpectations`
when using global expectation methods with no arguments.
@koic
Copy link
Member

koic commented Apr 12, 2020

Thanks for the feedback. I opened #76.

@koic koic closed this as completed in #76 Apr 13, 2020
koic added a commit that referenced this issue Apr 13, 2020
…ations_using_without_arguments

[Fix #75] Fix a false negative for `Minitest/GlobalExpectations`
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.

2 participants