Class: Crspec::ExpectationTarget

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

Instance Method Summary collapse

Constructor Details

#initialize(actual) ⇒ ExpectationTarget

Returns a new instance of ExpectationTarget.



9
10
11
# File 'lib/crspec/expectations.rb', line 9

def initialize(actual)
  @actual = actual
end

Instance Method Details

#not_to(matcher = nil, &block) ⇒ Object Also known as: to_not



22
23
24
25
26
27
28
29
# File 'lib/crspec/expectations.rb', line 22

def not_to(matcher = nil, &block)
  matcher ||= block
  if matcher.matches?(@actual)
    msg = matcher.respond_to?(:failure_message_when_negated) ? matcher.failure_message_when_negated : "Expected matcher not to match"
    raise ExpectationNotMetError, msg
  end
  true
end

#to(matcher = nil, &block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/crspec/expectations.rb', line 13

def to(matcher = nil, &block)
  matcher ||= block
  return matcher.setup_expect(@actual) if matcher.respond_to?(:setup_expect)

  raise ExpectationNotMetError, matcher.failure_message unless matcher.matches?(@actual)

  true
end