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.

Examples:

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

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:

ExpectationTarget.new { block of code }

Yield Parameters:

  • actual

    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 Method Details

#not_to(definition) ⇒ Boolean

Evaluate to a negative assertion.

Parameters:

  • definition (Hash, Symbol)

Returns:

  • (Boolean)

    pass or fail the spec



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

def not_to(definition)
  match?(definition).equal?(false) || fail(Failure)
end

#to(definition) ⇒ Boolean

Evaluate to a positive assertion.

Parameters:

  • definition (Hash, Symbol)

Returns:

  • (Boolean)

    pass or fail the spec



29
30
31
# File 'lib/expect/expectation_target.rb', line 29

def to(definition)
  match?(definition) || fail(Failure)
end