检查 Minitest 文件的代码风格。
A RuboCop extension focused on enforcing Minitest best practices and coding conventions. The library is based on the guidelines outlined in the community Minitest Style Guide.
Just install the rubocop-minitest gem
$ gem install rubocop-minitestor if you use bundler put this in your Gemfile
gem 'rubocop-minitest', require: falseYou need to tell RuboCop to load the Minitest extension. There are three ways to do this:
Put this into your .rubocop.yml.
plugins: rubocop-minitestAlternatively, use the following array notation when specifying multiple extensions.
plugins:
- rubocop-other-extension
- rubocop-minitestNow you can run rubocop and it will automatically load the RuboCop Minitest
cops together with the standard cops.
[!NOTE] The plugin system is supported in RuboCop 1.72+. In earlier versions, use
requireinstead ofplugins.
$ rubocop --plugin rubocop-minitestrequire 'rubocop/rake_task'
RuboCop::RakeTask.new do |task|
task.plugins 1 }
end
def target_ruby_version
3.0
end
endTo change them for a single test, assign them in the test method. This makes it possible for tests targeting different Ruby versions to live in the same test class:
class MyCopTest < RuboCop::TestCase
def test_registers_offense_on_ruby31
self.target_ruby_version = 3.1
assert_offense(<<~RUBY)
bad_method
^^^^^^^^^^ Use `good_method` instead of `bad_method`.
RUBY
end
def test_does_not_register_offense_on_ruby30
self.target_ruby_version = 3.0
assert_no_offenses(<<~RUBY)
bad_method
RUBY
end
endThe default configuration of extensions registered as lint_roller plugins
is applied automatically. For other extensions, call RuboCop::ConfigLoader.inject_defaults!('path/to/default.yml')
in your test helper.
You can read a lot more about RuboCop Minitest in its official docs.
If you use RuboCop Minitest in your project, you can include one of these badges in your readme to let people know that your code is written following the community Minitest Style Guide. Here are the Markdown snippets for the two badges:
Checkout the contribution guidelines.
rubocop-minitest is MIT licensed. See the accompanying file for
the full text.
暂无开放 Issues,或尚未同步最近议题。