Module: RSpec::Expectations::Syntax

### Home Classes Methods

### In Files

- lib/rspec/expectations/syntax.rb

### Namespace

- MODULE RSpec::Expectations::Syntax::ExpectExpressionGenerator
- MODULE RSpec::Expectations::Syntax::ShouldExpressionGenerator

### Methods

- #default_should_host
- #disable_expect
- #disable_should
- #enable_expect
- #enable_should
- #expect
- #expect_enabled?
- #expression_generator
- #negative_expression
- #positive_expression
- #should
- #should_enabled?
- #should_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::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 42
    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 95
    def disable_expect(syntax_host = ::RSpec::Matchers)
      return unless expect_enabled?(syntax_host)

      syntax_host.module_eval do
        undef expect
      end

      ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should
    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 66
    def disable_should(syntax_host = default_should_host)
      return unless should_enabled?(syntax_host)

      syntax_host.module_eval do
        undef should
        undef should_not
      end

      ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should
    end

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

@api private Enables the `expect` syntax.

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

      syntax_host.module_eval do
        def expect(*target, &target_block)
          target << target_block if block_given?
          raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
          ::RSpec::Expectations::ExpectationTarget.new(target.first)
        end
      end

      ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if should_enabled?
    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 48
    def enable_should(syntax_host = default_should_host)
      return if should_enabled?(syntax_host)

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

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

      ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if expect_enabled?
    end

expect(*target, &target_block) click to toggle source

    # File lib/rspec/expectations/syntax.rb, line 83
    def expect(*target, &target_block)
      target << target_block if block_given?
      raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
      ::RSpec::Expectations::ExpectationTarget.new(target.first)
    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 113
    def expect_enabled?(syntax_host = ::RSpec::Matchers)
      syntax_host.method_defined?(:expect)
    end

expression_generator() click to toggle source

@api private Selects which expression generator to use based on the configured syntax.

    # File lib/rspec/expectations/syntax.rb, line 131
    def expression_generator
      if expect_enabled?
        ExpectExpressionGenerator
      else
        ShouldExpressionGenerator
      end
    end

negative_expression(target_expression, matcher_expression) click to toggle source

@api private Generates a negative expectation expression.

    # File lib/rspec/expectations/syntax.rb, line 125
    def negative_expression(target_expression, matcher_expression)
      expression_generator.negative_expression(target_expression, matcher_expression)
    end

positive_expression(target_expression, matcher_expression) click to toggle source

@api private Generates a positive expectation expression.

    # File lib/rspec/expectations/syntax.rb, line 119
    def positive_expression(target_expression, matcher_expression)
      expression_generator.positive_expression(target_expression, matcher_expression)
    end

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

    # File lib/rspec/expectations/syntax.rb, line 52
    def should(matcher=nil, message=nil, &block)
      ::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 107
    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 56
    def should_not(matcher=nil, message=nil, &block)
      ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.