Class: RSpec::Expectations::ExpectationTarget

### Home Classes Methods

### In Files

- lib/rspec/expectations/expectation_target.rb

### Parent

Object

### Methods

- ::for
- ::new
- #not_to
- #to
- #to_not

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::AliasedMatcher
- RSpec::Matchers::AliasedMatcherWithOperatorSupport
- RSpec::Matchers::AliasedNegatedMatcher
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::All
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeBetween
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalsey
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTruthy
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::CaptureStderr
- RSpec::Matchers::BuiltIn::CaptureStdout
- RSpec::Matchers::BuiltIn::CaptureStreamToTempfile
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::ChangeDetails
- RSpec::Matchers::BuiltIn::ChangeFromValue
- RSpec::Matchers::BuiltIn::ChangeRelatively
- RSpec::Matchers::BuiltIn::ChangeToValue
- RSpec::Matchers::BuiltIn::Compound
- RSpec::Matchers::BuiltIn::Compound::And
- RSpec::Matchers::BuiltIn::Compound::NestedEvaluator
- RSpec::Matchers::BuiltIn::Compound::Or
- RSpec::Matchers::BuiltIn::Compound::SequentialEvaluator
- RSpec::Matchers::BuiltIn::ContainExactly
- RSpec::Matchers::BuiltIn::ContainExactly::PairingsMaximizer
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Exist::ExistenceTest
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::HaveAttributes
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::NullCapture
- RSpec::Matchers::BuiltIn::OperatorMatcher
- RSpec::Matchers::BuiltIn::Output
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::SpecificValuesChange
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartOrEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Composable
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::DefaultImplementations
- RSpec::Matchers::DSL::Macros
- RSpec::Matchers::DSL::Macros::Deprecated
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::ExpectedsForMultipleDiffs
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- RSpec::Matchers::Pretty
- BasicObject
- Object

No matching classes.

# 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.

### Public Class Methods

for(value, block) click to toggle source

@private

    # File lib/rspec/expectations/expectation_target.rb, line 30
    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
        new(value)
      end
    end

new(value) click to toggle source

@api private

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

### Public Instance Methods

not_to(matcher=nil, message=nil, &block) click to toggle source

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

    expect(value).not_to eq(5)

@param [Matcher]

    matcher

@param [String or Proc] message optional message to display when the expectation fails @return [Boolean] false if the negative expectation succeeds (else raises) @see RSpec::Matchers

    # File lib/rspec/expectations/expectation_target.rb, line 65
    def not_to(matcher=nil, message=nil, &block)
      prevent_operator_matchers(:not_to) unless matcher
      RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block)
    end

Also aliased as: to_not
to(matcher=nil, message=nil, &block) click to toggle source

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

    expect(value).to eq(5)
    expect { perform }.to raise_error

@param [Matcher]

    matcher

@param [String or Proc] message optional message to display when the expectation fails @return [Boolean] true if the expectation succeeds (else raises) @see RSpec::Matchers

    # File lib/rspec/expectations/expectation_target.rb, line 52
    def to(matcher=nil, message=nil, &block)
      prevent_operator_matchers(:to) unless matcher
      RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block)
    end

to_not(matcher=nil, message=nil, &block) click to toggle source
Alias for: not_to

[Validate]

Generated with the Darkfish Rdoc Generator 2.