Class: RuboCop::Cop::InternalAffairs::ExampleDescription
- Defined in:
- lib/rubocop/cop/internal_affairs/example_description.rb
Overview
Checks that RSpec examples that use ‘expects_offense` or `expects_no_offenses` do not have conflicting descriptions.
Constant Summary collapse
- MSG =
'Description does not match use of `%<method_name>s`.'
- RESTRICT_ON_SEND =
%i[ expect_offense expect_no_offenses expect_correction expect_no_corrections ].to_set.freeze
- EXPECT_NO_OFFENSES_INCORRECT_DESCRIPTIONS =
[ /^(adds|registers|reports|finds) (an? )?offense/, /^(flags|handles|works)\b/ ].freeze
- EXPECT_OFFENSE_INCORRECT_DESCRIPTIONS =
[ /^(does not|doesn't) (register|find|flag|report)/, /^(does not|doesn't) add (a|an|any )?offense/, /^accepts\b/ ].freeze
- EXPECT_NO_CORRECTIONS_INCORRECT_DESCRIPTIONS =
[/^(auto[- ]?)?correct/].freeze
- EXPECT_CORRECTION_INCORRECT_DESCRIPTIONS =
[ /\b(does not|doesn't) (auto[- ]?)?correct/ ].freeze
Class Attribute Summary collapse
-
.descriptions ⇒ Object
Returns the value of attribute descriptions.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, autocorrect_incompatible_with, badge, #begin_investigation, callbacks_needed, #callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_new_investigation, #on_other_file, #parse, #ready, #relevant_file?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from RuboCop::Cop::IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Class Attribute Details
.descriptions ⇒ Object
Returns the value of attribute descriptions.
30 31 32 |
# File 'lib/rubocop/cop/internal_affairs/example_description.rb', line 30 def descriptions @descriptions end |
Instance Method Details
#offense_example?(node) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/rubocop/cop/internal_affairs/example_description.rb', line 60 def_node_matcher :offense_example?, <<~PATTERN (block (send _ {:it :specify} $_description) _args `(send nil? %RESTRICT_ON_SEND ...) ) PATTERN |
#on_send(node) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubocop/cop/internal_affairs/example_description.rb', line 68 def on_send(node) parent = node.each_ancestor(:block).first return unless parent && (description = offense_example?(parent)) method_name = node.method_name = format(MSG, method_name: method_name) regexp_group = self.class.const_get("#{method_name}_incorrect_descriptions".upcase) check_description(description, regexp_group, ) end |