class RSpec::Expectations::ExpectationTarget

Wraps the target of an expectation.

@example

expect(something)       # => ExpectationTarget wrapping something
expect { do_something } # => ExpectationTarget wrapping the block

# used with `to`
expect(actual).to eq(3)

# with `not_to`
expect(actual).not_to eq(3)

@note ‘ExpectationTarget` is not intended to be instantiated

directly by users. Use `expect` instead.

Constants

UndefinedValue

@private Used as 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.

Attributes

@note this name aligns with ‘Minitest::Expectation` so that our

{InstanceMethods} module can be included in that class when
used in a Minitest context.

@return [Object] the target of the expectation

Public Class Methods

@private

# File rspec-expectations/lib/rspec/expectations/expectation_target.rb, line 36
def self.for(value, block)
  if UndefinedValue.equal?(value)
    unless block
      raise ArgumentError, "You must pass either an argument or a block to `expect`."
    end
    BlockExpectationTarget.new(block)
  elsif block
    raise ArgumentError, "You cannot pass both an argument and a block to `expect`."
  else
    ValueExpectationTarget.new(value)
  end
end

@api private

# File rspec-expectations/lib/rspec/expectations/expectation_target.rb, line 31
def initialize(value)
  @target = value
end