Class: RSpec::ExpectationTarget::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/r_spec/expectation_target/base.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.

Note:

‘RSpec::ExpectationTarget::Base` is not intended to be instantiated directly by users. Use `expect` instead.

Abstract expectation target base class.

Direct Known Subclasses

Block, Value

Instance Method Summary collapse

Constructor Details

#initialize(actual) ⇒ Base

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.

Instantiate a new expectation target.

Parameters:

  • actual (#object_id)

    The actual value of the code to evaluate.



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

def initialize(actual)
  @actual = actual
end

Instance Method Details

#not_to(matcher) ⇒ nil

Runs the given expectation, passing if ‘matcher` returns false.

Examples:

_Absolute prohibition_ definition

expect { "foo".size }.not_to be(4)

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:

  • (nil)

    Write a message to STDOUT.

Raises:

  • (SystemExit)

    Terminate execution immediately by calling ‘Kernel.exit(false)` with a failure message written to STDERR.



48
49
50
# File 'lib/r_spec/expectation_target/base.rb', line 48

def not_to(matcher)
  absolute_requirement(matcher: matcher, negate: true)
end

#to(matcher) ⇒ nil

Runs the given expectation, passing if ‘matcher` returns true.

Examples:

_Absolute requirement_ definition

expect { "foo".upcase }.to eq("foo")

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:

  • (nil)

    Write a message to STDOUT.

Raises:

  • (SystemExit)

    Terminate execution immediately by calling ‘Kernel.exit(false)` with a failure message written to STDERR.



33
34
35
# File 'lib/r_spec/expectation_target/base.rb', line 33

def to(matcher)
  absolute_requirement(matcher: matcher, negate: false)
end