Class: Smartest::AndMatcher

Inherits:
CompoundMatcher show all
Defined in:
lib/smartest/matchers.rb

Constant Summary

Constants inherited from CompoundMatcher

CompoundMatcher::NEGATED_EXPECTATION_ERROR

Instance Attribute Summary

Attributes inherited from CompoundMatcher

#matchers

Instance Method Summary collapse

Methods inherited from CompoundMatcher

#initialize, #negated_expectation_error, #supports_negated_expectation?

Methods inherited from Matcher

#and, #or

Constructor Details

This class inherits a constructor from Smartest::CompoundMatcher

Instance Method Details

#descriptionObject



175
176
177
# File 'lib/smartest/matchers.rb', line 175

def description
  joined_description(" and ")
end

#failure_messageObject



165
166
167
168
169
# File 'lib/smartest/matchers.rb', line 165

def failure_message
  message = "expected #{actual_description} to match all of #{description}"
  details = failure_messages
  details.empty? ? message : "#{message}; #{details.join('; ')}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/smartest/matchers.rb', line 144

def matches?(actual)
  reset_result
  @actual = actual

  if composed_block_expectation?(actual)
    run_composed_block_expectation(actual)
    return @failed_matchers.empty?
  end

  @matchers.each do |matcher|
    if matcher.matches?(actual)
      @matched_matchers << matcher
    else
      @failed_matchers << matcher
      return false
    end
  end

  true
end

#negated_failure_messageObject



171
172
173
# File 'lib/smartest/matchers.rb', line 171

def negated_failure_message
  "expected #{actual_description} not to match all of #{description}"
end