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 needs method chain support #64

Closed
yahonda opened this issue Mar 9, 2020 · 0 comments · Fixed by #65
Closed

Minitest/GlobalExpectations cop needs method chain support #64

yahonda opened this issue Mar 9, 2020 · 0 comments · Fixed by #65
Labels
bug Something isn't working

Comments

@yahonda
Copy link
Contributor

yahonda commented Mar 9, 2020

Thanks for releasing rubocop-minitest 0.7.0 which implements #60.

I'd like to apply this cop to google-cloud-storage gem and found it needs method chain support.

Expected behavior

Minitest/GlobalExpectations cop corrects method chain correctly.

Actual behavior

Minitest/GlobalExpectations cop adds _() only the last method name then the test modified is getting error as follows.

% ruby method_chain.rb
Fetching gem metadata from https://rubygems.org/..................
Resolving dependencies...
Using bundler 2.1.2
Using minitest 5.14.0
Run options: --seed 39348

# Running:

E

Finished in 0.000494s, 2024.2915 runs/s, 0.0000 assertions/s.

  1) Error:
Greeting#test_0001_must say hello world in lower case:
NameError: undefined local variable or method `downcase' for #<#<Class:0x00007f880341dce0>:0x00007f88033f45e8>
    method_chain.rb:25:in `block (2 levels) in <main>'

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

Steps to reproduce the problem

  • Create a method_chain.rb
# frozen_string_literal: true

require 'bundler/inline'

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

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

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

  it 'must say hello world in lower case' do
    @foo.say_hello.downcase.must_equal 'hello, world!'
    # Actual auto correct result
    # @foo.say_hello._(downcase).must_equal 'hello, world!'
    #
    # Expected auto correct result
    # _(@foo.say_hello.downcase).must_equal 'hello, world!'
  end
end
  • Install Ruby 2.7.0 (i.e. rbenv install 2.7.0 ; rbenv global 2.7.0)
  • gem install rubocop-minitest
  • Run ruby method_chain.rb to see if this file shows DEPRECATED: global use of must_equal from method_chain.rb:25. Use _(obj).must_equal instead. This will fail in Minitest 6. and finishes successfully
  • rubocop --require rubocop-minitest --only Minitest/GlobalExpectations method_chain.rb -a to auto-correct Minitest/GlobalExpectations cop
  • Run ruby method_chain.rb

RuboCop version

% rubocop -V
0.80.0 (using Parser 2.7.0.3, running on ruby 2.7.0 x86_64-darwin19)
@koic koic added the enhancement New feature or request label Mar 9, 2020
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Mar 9, 2020
tejasbubane added a commit to tejasbubane/rubocop-minitest that referenced this issue Mar 10, 2020
@koic koic added bug Something isn't working and removed enhancement New feature or request labels Mar 10, 2020
@koic koic closed this as completed in #65 Mar 12, 2020
koic added a commit that referenced this issue Mar 12, 2020
[Fix #64] Fix `Minitest/GlobalExpectations` autocorrection for chained methods
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
2 participants