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

TestFileName errors when encountering files without classes #225

Closed
coding-chimp opened this issue Jan 16, 2023 · 0 comments · Fixed by #227
Closed

TestFileName errors when encountering files without classes #225

coding-chimp opened this issue Jan 16, 2023 · 0 comments · Fixed by #227
Labels
bug Something isn't working

Comments

@coding-chimp
Copy link

After updating to v0.26.0, I'm seeing errors like these in a gem I'm working on:

An error occurred while Minitest/TestFileName cop was inspecting PATH_TO_GEM/test/dummy/config/initializers/content_security_policy.rb.
An error occurred while Minitest/TestFileName cop was inspecting PATH_TO_GEM/test/dummy/config/initializers/inflections.rb.
An error occurred while Minitest/TestFileName cop was inspecting PATH_TO_GEM/test/dummy/config/initializers/permissions_policy.rb.

Those files are part of a dummy Rails application we use for testing. They mainly contain comments.

This is the backtrace I'm getting when running rubocop -d:

undefined method `class_type?' for nil:NilClass
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-minitest-0.26.0/lib/rubocop/cop/minitest/test_file_name.rb:32:in `test_file?'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-minitest-0.26.0/lib/rubocop/cop/minitest/test_file_name.rb:24:in `on_new_investigation'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:154:in `block (2 levels) in invoke'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:165:in `with_cop_error_handling'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:154:in `block in invoke'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:154:in `each'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:154:in `invoke'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/commissioner.rb:84:in `investigate'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cop/team.rb:97:in `investigate'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:322:in `inspect_file'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:266:in `block in do_inspection_loop'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:300:in `block in iterate_until_no_changes'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:293:in `loop'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:293:in `iterate_until_no_changes'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:262:in `do_inspection_loop'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:143:in `block in file_offenses'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:168:in `file_offense_cache'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:142:in `file_offenses'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:133:in `process_file'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:114:in `block in each_inspected_file'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:113:in `each'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:113:in `reduce'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:113:in `each_inspected_file'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:99:in `inspect_files'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/runner.rb:52:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli.rb:72:in `run_command'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli.rb:79:in `execute_runners'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/lib/rubocop/cli.rb:48:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/exe/rubocop:19:in `block in <top (required)>'
/opt/rubies/3.2.0/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/Users/codechimp/.gem/ruby/3.2.0/gems/rubocop-1.43.0/exe/rubocop:19:in `<top (required)>'
/Users/codechimp/.gem/ruby/3.2.0/bin/rubocop:25:in `load'
/Users/codechimp/.gem/ruby/3.2.0/bin/rubocop:25:in `<top (required)>'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli/exec.rb:58:in `load'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli/exec.rb:23:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli.rb:484:in `exec'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli.rb:31:in `dispatch'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/cli.rb:25:in `start'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/exe/bundle:48:in `block in <top (required)>'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/Users/codechimp/.gem/ruby/3.2.0/gems/bundler-2.3.5/exe/bundle:36:in `<top (required)>'
/Users/codechimp/.gem/ruby/3.2.0/bin/bundle:25:in `load'
/Users/codechimp/.gem/ruby/3.2.0/bin/bundle:25:in `<main>'

Expected behavior

The TestFileName cop should run without errors and not register any offenses for empty files.

Actual behavior

The TestFileName cop errors.

Steps to reproduce the problem

Add an empty file to the test directory.

RuboCop version

> rubocop -V                                                                                                                                                                                                                                                       3.2.0 dependabot/bundler/rubocop-minitest-0.26.0@b7f1008 ✗
1.43.0 (using Parser 3.2.0.0, rubocop-ast 1.24.1, running on ruby 3.2.0) [arm64-darwin21.5.0]
  - rubocop-minitest 0.26.0
  - rubocop-rake 0.6.0
@koic koic added the bug Something isn't working label Jan 16, 2023
koic added a commit to koic/rubocop-minitest that referenced this issue Jan 16, 2023
Fixes rubocop#225.

This PR fixes an error for `Minitest/TestFileName` when using empty file.
@koic koic closed this as completed in #227 Jan 16, 2023
koic added a commit that referenced this issue Jan 16, 2023
…_name

[Fix #225] Fix an error for `Minitest/TestFileName`
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