Class: RSpec::Expectations::ExpectationTarget

### Home Classes Methods

### In Files

- lib/rspec/expectations/expectation_target.rb

### Parent

Object

### Methods

- ::disable_deprecated_should
- ::enable_deprecated_should
- ::new
- #not_to
- #should
- #should_not
- #to
- #to_not

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- 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::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- 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::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Expectations::ExpectationTarget

Wraps the target of an expectation. @example

    expect(something) # => ExpectationTarget wrapping something

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

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

### Attributes

deprecated_should_enabled[RW]
deprecated_should_enabled?[RW]

### Public Class Methods

disable_deprecated_should() click to toggle source

    # File lib/rspec/expectations/expectation_target.rb, line 67
    def self.disable_deprecated_should
      return unless deprecated_should_enabled?

      remove_method :should
      remove_method :should_not

      self.deprecated_should_enabled = false
    end

enable_deprecated_should() click to toggle source

    # File lib/rspec/expectations/expectation_target.rb, line 51
    def self.enable_deprecated_should
      return if deprecated_should_enabled?

      def should(*args)
        RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`"
        @target.should(*args)
      end

      def should_not(*args)
        RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`"
        @target.should_not(*args)
      end

      self.deprecated_should_enabled = true
    end

new(target) click to toggle source

@api private

    # File lib/rspec/expectations/expectation_target.rb, line 19
    def initialize(target)
      @target = target
    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] 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 45
    def not_to(matcher=nil, message=nil, &block)
      prevent_operator_matchers(:not_to, matcher)
      RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block)
    end

Also aliased as: to_not
should(*args) click to toggle source

    # File lib/rspec/expectations/expectation_target.rb, line 54
    def should(*args)
      RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`"
      @target.should(*args)
    end

should_not(*args) click to toggle source

    # File lib/rspec/expectations/expectation_target.rb, line 59
    def should_not(*args)
      RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`"
      @target.should_not(*args)
    end

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] 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 32
    def to(matcher=nil, message=nil, &block)
      prevent_operator_matchers(:to, 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.