Class: Expect::ExpectationTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/expect/expectation_target.rb

Overview

Wraps the target of an expectation. This class is responsible for reporting if the expectation is true or false.

Examples:

ExpectationTarget.new { 42 }.to Equal: 42 # => true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&actual) ⇒ ExpectationTarget

Create a new expection target

Examples:

new { 42 }.to Equal: 42 # => true

Parameters:

  • actual (Proc)

    the value which is compared with the expected value.



16
17
18
# File 'lib/expect/expectation_target.rb', line 16

def initialize(&actual)
  @actual = actual
end

Instance Attribute Details

#actualBasicObject (readonly)

Returns the object to be compared with the expected one though the matcher.

Returns:

  • (BasicObject)

    the object to be compared with the expected one though the matcher.



23
24
25
# File 'lib/expect/expectation_target.rb', line 23

def actual
  @actual
end

Instance Method Details

#not_to(definition) ⇒ Boolean

Evaluate to a negative assertion.

Parameters:

  • definition (Array, Hash, Symbol)

    The definition of the expected value.

Returns:

  • (Boolean)

    report if the expectation is true or false



40
41
42
# File 'lib/expect/expectation_target.rb', line 40

def not_to(definition)
  !to(definition)
end

#to(definition) ⇒ Boolean

Evaluate to a positive assertion.

Parameters:

  • definition (Array, Hash, Symbol)

    The definition of the expected value.

Returns:

  • (Boolean)

    report if the expectation is true or false



31
32
33
# File 'lib/expect/expectation_target.rb', line 31

def to(definition)
  matcher(definition).matches?(&actual)
end