Class: Expect::ExpectationTarget Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new expection target

Examples:

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

Parameters:

  • actual (Proc)

    the value which is compared with the expected value.



18
19
20
# File 'lib/expect/expectation_target.rb', line 18

def initialize(&actual)
  @actual = actual
end

Instance Attribute Details

#actualObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def actual
  @actual
end

Instance Method Details

#not_to(definition) ⇒ Boolean

Evaluate to a negative assertion.

Parameters:

  • definition (Hash, Symbol)

Returns:

  • (Boolean)

    report if the expectation is not true or not false



42
43
44
# File 'lib/expect/expectation_target.rb', line 42

def not_to(definition)
  !to(definition)
end

#to(definition) ⇒ Boolean

Evaluate to a positive assertion.

Parameters:

  • definition (Hash, Symbol)

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