Module: RSpec::Expectations::Syntax

### Home Classes Methods

### In Files

- lib/rspec/expectations/syntax.rb

### Methods

- #default_should_host
- #disable_expect
- #disable_should
- #enable_expect
- #enable_should
- #expect
- #expect_enabled?
- #should
- #should_enabled?
- #should_not
- #warn_about_should!
- #warn_about_should_unless_configured

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::BlockExpectationTarget
- RSpec::Expectations::Configuration
- RSpec::Expectations::ExpectationHelper
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::FailureAggregator
- RSpec::Expectations::LegacyMacherAdapter
- RSpec::Expectations::LegacyMatcherAdapter
- RSpec::Expectations::LegacyMatcherAdapter::RSpec1
- RSpec::Expectations::LegacyMatcherAdapter::RSpec2
- RSpec::Expectations::MultipleExpectationsNotMetError
- 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::BaseMatcher::HashFormatting
- 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::EnglishPhrasing
- RSpec::Matchers::ExpectedsForMultipleDiffs
- RSpec::Matchers::FailMatchers
- RSpec::Matchers::MatcherDelegator
- RSpec::Matchers::MatcherProtocol
- BasicObject
- Object

No matching classes.

# RSpec::Expectations::Syntax

@api private Provides methods for enabling and disabling the available syntaxes provided by rspec-expectations.

### Public Instance Methods

default_should_host() click to toggle source

@api private Determines where we add `should` and `should_not`.

    # File lib/rspec/expectations/syntax.rb, line 11
    def default_should_host
      @default_should_host ||= ::Object.ancestors.last
    end

disable_expect(syntax_host=::RSpec::Matchers) click to toggle source

@api private Disables the `expect` syntax.

    # File lib/rspec/expectations/syntax.rb, line 80
    def disable_expect(syntax_host=::RSpec::Matchers)
      return unless expect_enabled?(syntax_host)

      syntax_host.module_exec do
        undef expect
      end
    end

disable_should(syntax_host=default_should_host) click to toggle source

@api private Disables the `should` syntax.

    # File lib/rspec/expectations/syntax.rb, line 57
    def disable_should(syntax_host=default_should_host)
      return unless should_enabled?(syntax_host)

      syntax_host.module_exec do
        undef should
        undef should_not
      end
    end

enable_expect(syntax_host=::RSpec::Matchers) click to toggle source

@api private Enables the `expect` syntax.

    # File lib/rspec/expectations/syntax.rb, line 68
    def enable_expect(syntax_host=::RSpec::Matchers)
      return if expect_enabled?(syntax_host)

      syntax_host.module_exec do
        def expect(value=::RSpec::Expectations::ExpectationTarget::UndefinedValue, &block)
          ::RSpec::Expectations::ExpectationTarget.for(value, block)
        end
      end
    end

enable_should(syntax_host=default_should_host) click to toggle source

@api private Enables the `should` syntax.

    # File lib/rspec/expectations/syntax.rb, line 38
    def enable_should(syntax_host=default_should_host)
      @warn_about_should = false if syntax_host == default_should_host
      return if should_enabled?(syntax_host)

      syntax_host.module_exec do
        def should(matcher=nil, message=nil, &block)
          ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
          ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
        end

        def should_not(matcher=nil, message=nil, &block)
          ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
          ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
        end
      end
    end

expect(value=::RSpec::Expectations::ExpectationTarget::UndefinedValue, &block) click to toggle source

    # File lib/rspec/expectations/syntax.rb, line 72
    def expect(value=::RSpec::Expectations::ExpectationTarget::UndefinedValue, &block)
      ::RSpec::Expectations::ExpectationTarget.for(value, block)
    end

expect_enabled?(syntax_host=::RSpec::Matchers) click to toggle source

@api private Indicates whether or not the `expect` syntax is enabled.

    # File lib/rspec/expectations/syntax.rb, line 96
    def expect_enabled?(syntax_host=::RSpec::Matchers)
      syntax_host.method_defined?(:expect)
    end

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

    # File lib/rspec/expectations/syntax.rb, line 43
    def should(matcher=nil, message=nil, &block)
      ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
      ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
    end

should_enabled?(syntax_host=default_should_host) click to toggle source

@api private Indicates whether or not the `should` syntax is enabled.

    # File lib/rspec/expectations/syntax.rb, line 90
    def should_enabled?(syntax_host=default_should_host)
      syntax_host.method_defined?(:should)
    end

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

    # File lib/rspec/expectations/syntax.rb, line 48
    def should_not(matcher=nil, message=nil, &block)
      ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__)
      ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
    end

warn_about_should!() click to toggle source

@api private Instructs rspec-expectations to warn on first usage of `should` or `should_not`. Enabled by default. This is largely here to facilitate testing.

    # File lib/rspec/expectations/syntax.rb, line 18
    def warn_about_should!
      @warn_about_should = true
    end

warn_about_should_unless_configured(method_name) click to toggle source

@api private Generates a deprecation warning for the given method if no warning has already been issued.

    # File lib/rspec/expectations/syntax.rb, line 25
    def warn_about_should_unless_configured(method_name)
      return unless @warn_about_should

      RSpec.deprecate(
        "Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax",
        :replacement => "the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }`"
      )

      @warn_about_should = false
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.