Class: RuboCop::Cop::RSpecParity::SufficientContexts
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RSpecParity::SufficientContexts
- Includes:
- DepartmentConfig, SpecFileFinder
- Defined in:
- lib/rubocop/cop/rspec_parity/sufficient_contexts.rb
Overview
Ensures that specs have at least as many contexts as the method has branches.
This cop helps ensure thorough test coverage by checking that complex methods with multiple branches (if/elsif/else, case/when, &&, ||, ternary) have corresponding context blocks in their specs to test each branch.
Constant Summary collapse
- MSG =
"Method `%<method_name>s` has %<branches>d %<branch_word>s but only %<contexts>d %<context_word>s " \ "in spec. Add %<missing>d more %<missing_word>s to cover all branches."
- TRACED_SUFFIX =
" (including branches from: %<traced>s)"- APP_DIR_PATTERN =
%r{/app/}- EXCLUDED_METHODS =
%w[initialize].freeze
- EXCLUDED_PATTERNS =
[ /^before_/, /^after_/, /^around_/, /^validate_/, /^autosave_/ ].freeze
Constants included from DepartmentConfig
DepartmentConfig::SHARED_CONFIG_DEFAULTS
Instance Method Summary collapse
-
#initialize(config = nil, options = nil) ⇒ SufficientContexts
constructor
A new instance of SufficientContexts.
- #on_def(node) ⇒ Object
- #on_defs(node) ⇒ Object
Constructor Details
#initialize(config = nil, options = nil) ⇒ SufficientContexts
Returns a new instance of SufficientContexts.
62 63 64 65 66 67 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 62 def initialize(config = nil, = nil) super @ignore_memoization = cop_config.fetch("IgnoreMemoization", true) @trace_single_use_private = cop_config.fetch("TraceSingleUsePrivateMethods", true) @call_graphs = {}.compare_by_identity end |
Instance Method Details
#on_def(node) ⇒ Object
69 70 71 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 69 def on_def(node) check_method(node) end |
#on_defs(node) ⇒ Object
73 74 75 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 73 def on_defs(node) check_method(node) end |