Module: RSpec::Clone::ExpectationTarget Private

Defined in:
lib/r_spec/clone/expectation_target.rb,
lib/r_spec/clone/expectation_target/base.rb,
lib/r_spec/clone/expectation_target/block.rb,
lib/r_spec/clone/expectation_target/value.rb

Overview

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

Wraps the target of an expectation.

Defined Under Namespace

Classes: Base, Block, Value

Class Method Summary collapse

Class Method Details

.call(undefined_value, value, block) ⇒ Block, Value

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.

Returns The wrapped target of an expectation.

Parameters:

  • undefined_value

    A sentinel value to be able to tell when the user did not pass an argument. We can't use `nil` for that because `nil` is a valid value to pass.

  • value (#object_id, nil)

    An actual value.

  • block (#call, nil)

    A code to evaluate.

Returns:

  • (Block, Value)

    The wrapped target of an expectation.


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/r_spec/clone/expectation_target.rb', line 17

def self.call(undefined_value, value, block)
  if undefined_value.equal?(value)
    raise ::ArgumentError, "Pass either an argument or a block" unless block

    Block.new(block)
  else
    raise ::ArgumentError, "Can't pass both an argument and a block" if block

    Value.new(value)
  end
end