Class: RuboCop::Cop::RSpecParity::SufficientContexts::BranchTally

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubocop/cop/rspec_parity/sufficient_contexts.rb

Overview

Branch tally split into guard-clause “fire” branches vs. every other branch. A sequence of guard clauses (‘return/raise/next … if/unless`) shares a single “all guards pass” fall-through, so that happy path is counted once for the whole method (see #branches_from) rather than once per guard — which previously inflated guard-heavy methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#guardObject

Returns the value of attribute guard

Returns:

  • (Object)

    the current value of guard



71
72
73
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 71

def guard
  @guard
end

#regularObject

Returns the value of attribute regular

Returns:

  • (Object)

    the current value of regular



71
72
73
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 71

def regular
  @regular
end

Instance Method Details

#+(other) ⇒ Object



72
73
74
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 72

def +(other)
  BranchTally.new(guard + other.guard, regular + other.regular)
end

#totalObject



76
77
78
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 76

def total
  guard + regular
end