Class: Crspec::Matchers::CompoundAndMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/crspec/matchers.rb

Direct Known Subclasses

CompoundOrMatcher

Instance Method Summary collapse

Constructor Details

#initialize(first, second) ⇒ CompoundAndMatcher

Returns a new instance of CompoundAndMatcher.



30
31
32
33
# File 'lib/crspec/matchers.rb', line 30

def initialize(first, second)
  @first = first
  @second = second
end

Instance Method Details

#and(other) ⇒ Object



52
53
54
# File 'lib/crspec/matchers.rb', line 52

def and(other)
  CompoundAndMatcher.new(self, other)
end

#failure_messageObject



41
42
43
44
45
46
# File 'lib/crspec/matchers.rb', line 41

def failure_message
  messages = []
  messages << @first.failure_message unless @first_matched
  messages << @second.failure_message unless @second_matched
  messages.join("\n...and:\n")
end

#failure_message_when_negatedObject



48
49
50
# File 'lib/crspec/matchers.rb', line 48

def failure_message_when_negated
  "Expected compound matcher not to match"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/crspec/matchers.rb', line 35

def matches?(actual)
  @first_matched = @first.matches?(actual)
  @second_matched = @second.matches?(actual)
  @first_matched && @second_matched
end

#or(other) ⇒ Object



56
57
58
# File 'lib/crspec/matchers.rb', line 56

def or(other)
  CompoundOrMatcher.new(self, other)
end