Skip to content

Commit

Permalink
Merge pull request #227 from koic/fix_an_error_for_minitest_test_file…
Browse files Browse the repository at this point in the history
…_name

[Fix #225] Fix an error for `Minitest/TestFileName`
  • Loading branch information
koic committed Jan 16, 2023
2 parents 7fed470 + 99d9fc1 commit d30055e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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

0 comments on commit d30055e

Please sign in to comment.