Class: Smartest::OrMatcher

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



207
208
209
# File 'lib/smartest/matchers.rb', line 207

def description
  joined_description(" or ")
end

#failure_messageObject



197
198
199
200
201
# File 'lib/smartest/matchers.rb', line 197

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/smartest/matchers.rb', line 181

def matches?(actual)
  reset_result
  @actual = actual

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

    @failed_matchers << matcher
  end

  false
end

#negated_failure_messageObject



203
204
205
# File 'lib/smartest/matchers.rb', line 203

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