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

API:

  • public

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:

  • the value which is compared with the expected value.

API:

  • public



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:

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

API:

  • public



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:

  • The definition of the expected value.

Returns:

  • report if the expectation is true or false

API:

  • public



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:

  • The definition of the expected value.

Returns:

  • report if the expectation is true or false

API:

  • public



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

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