Class: RuboCop::Cop::Kaizo::SpecComment
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Kaizo::SpecComment
- Includes:
- AllowedPattern
- Defined in:
- lib/rubocop/cop/kaizo/spec_comment.rb
Overview
Checks for comments in spec files.
A comment in a spec is almost always a sign that the spec is doing the
job of its own description. If you need a sentence to explain what an
example sets up or asserts, that sentence usually wants to be a
context/it description, a clearer example name, or another example --
not prose riding alongside the code.
By default only *_spec.rb files are inspected (see Include). Magic
comments (# frozen_string_literal: true, # encoding: ...), RuboCop
directives (any # rubocop: comment), and shebangs are
never flagged; add further exemptions with AllowedPatterns. There is no
autocorrection: turning an explanation into a spec is a design decision.
Constant Summary collapse
- MSG =
"Avoid comments in specs. Express the intent as a `context`/`it` " \ "description or a clearer example instead.".freeze
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/kaizo/spec_comment.rb', line 38 def on_new_investigation processed_source.comments.each do |comment| next if allowed?(comment) add_offense(comment) end end |