Module: RuboCop::Minitest::AssertOffense
- Included in:
- TestCase
- Defined in:
- lib/rubocop/minitest/assert_offense.rb
Overview
Mixin for assert_offense and assert_no_offenses
This mixin makes it easier to specify strict offense assertions in a declarative and visual fashion. Just type out the code that should generate an offense, annotate code by writing '^'s underneath each character that should be highlighted, and follow the carets with a string (separated by a space) that is the message of the offense. You can include multiple offenses in one code snippet.
Autocorrection can be tested using assert_correction after
assert_offense.
If you do not want to specify an offense then use the
companion method assert_no_offenses. This method is a much
simpler assertion since it just inspects the source and checks
that there were no offenses. The assert_offense method has
to do more work by parsing out lines that contain carets.
If the code produces an offense that could not be autocorrected, you can
use assert_no_corrections after assert_offense.
The cop under test is derived from the test class name: FooTest resolves
the Foo constant in the test class's namespace, then RuboCop::Cop::Minitest::Foo.
Define a cop_class method in the test class to specify the cop explicitly:
class AssertNilTest < RuboCop::TestCase
private
def cop_class
RuboCop::Cop::Minitest::AssertNil
end
end
The configuration for the cop under test and the target Ruby version can be specified
by overriding cop_config, other_cops, or target_ruby_version in the test class:
To 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:
rubocop:disable Metrics/ModuleLength
Class Method Summary collapse
-
.integrate_plugins! ⇒ Object
Makes the default configuration of extensions registered as lint_roller plugins visible through
RuboCop::ConfigLoader.default_configuration.
Class Method Details
.integrate_plugins! ⇒ Object
Makes the default configuration of extensions registered as lint_roller plugins visible
through RuboCop::ConfigLoader.default_configuration.
Guarded by a mutex so that parallel test threads reaching their first assertion at the same time
do not integrate plugins twice or race on the lazy initialization of the default configuration.
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rubocop/minitest/assert_offense.rb', line 139 def integrate_plugins! PLUGIN_INTEGRATION_MUTEX.synchronize do next if @integrated_plugins plugins = Gem.loaded_specs.filter_map do |feature_name, feature_specification| feature_name if feature_specification.['default_lint_roller_plugin'] end RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, plugins) @integrated_plugins = true end end |