Class: RSpec::Expectations::ExpectationTarget

Inherits:
Object
  • Object
show all
Includes:
InstanceMethods
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/expectation_target.rb

Overview

Note:

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

Wraps the target of an expectation.

Examples:

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)

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

UndefinedValue =

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.

Module.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstanceMethods

#not_to, #to

Constructor Details

#initialize(value) ⇒ 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.

Returns a new instance of ExpectationTarget.



31
32
33
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/expectation_target.rb', line 31

def initialize(value)
  @target = value
end

Instance Attribute Details

#targetObject (readonly)

Note:

this name aligns with ‘Minitest::Expectation` so that our InstanceMethods module can be included in that class when used in a Minitest context.

Returns the target of the expectation.

Returns:

  • (Object)

    the target of the expectation



28
29
30
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/expectation_target.rb', line 28

def target
  @target
end

Class Method Details

.for(value, block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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