123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Expectations::ExpectationTarget

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Subclasses:
RSpec::Expectations::BlockExpectationTarget, RSpec::Expectations::ValueExpectationTarget
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: rspec-expectations/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)

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

InstanceMethods - Included

#not_to

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

#to

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

#to_not
#prevent_operator_matchers

Class Method Details

.for(value, block)

This method is for internal use only.
[ GitHub ]

  
# 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

Instance Attribute Details

#targetObject (readonly)

Note:

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

Returns:

  • (Object)

    the target of the expectation

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/expectation_target.rb', line 28

attr_reader :target