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

[Fix #225] Fix an error for Minitest/TestFileName #227

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_minitest_test_file_name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#225](https://github.com/rubocop/rubocop-minitest/issues/225): Fix an error for `Minitest/TestFileName` when using empty file. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/minitest/test_file_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class TestFileName < Base
MSG = 'Test file path should start with `test_` or end with `_test.rb`.'

def on_new_investigation
return unless test_file?(processed_source.ast)
return unless (ast = processed_source.ast)
return unless test_file?(ast)

add_global_offense(MSG) unless valid_file_name?
end
Expand Down
4 changes: 4 additions & 0 deletions test/rubocop/cop/minitest/test_file_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ def test_does_not_register_offense_for_non_test_classes
class Foo; end
RUBY
end

def test_does_not_register_offense_for_empty_file
assert_no_offenses('', 'lib/foo.rb')
end
end