Class: Crspec::Matchers::SatisfyMatcher

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

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected

Instance Method Summary collapse

Methods inherited from BaseMatcher

#and, #failure_message_when_negated, #or

Constructor Details

#initialize(description = nil, &block) ⇒ SatisfyMatcher

Returns a new instance of SatisfyMatcher.



506
507
508
509
510
# File 'lib/crspec/matchers.rb', line 506

def initialize(description = nil, &block)
  super(nil)
  @description = description
  @block = block
end

Instance Method Details

#failure_messageObject



517
518
519
# File 'lib/crspec/matchers.rb', line 517

def failure_message
  "Expected #{@actual.inspect} to satisfy #{@description || "the given block"}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


512
513
514
515
# File 'lib/crspec/matchers.rb', line 512

def matches?(actual)
  @actual = actual
  !!@block.call(actual)
end