Class: RSpec::Matchers::Configuration

### Home Classes Methods

### In Files

- lib/rspec/matchers/configuration.rb

### Parent

Object

### Methods

- #add_should_and_should_not_to
- #backtrace_formatter
- #color?
- #syntax
- #syntax=

### 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::Matchers::Configuration

Provides configuration options for rspec-expectations.

### Constants

NullBacktraceFormatter

  @api private

### Attributes

backtrace_formatter[W]

Sets or gets the backtrace formatter. The backtrace formatter should implement `format_backtrace(Array)`. This is used to format backtraces of errors handled by the `raise_error` matcher.

If you are using rspec-core, rspec-core's backtrace formatting will be used (including respecting the presence or absence of the `--backtrace` option).

@overload backtrace_formatter

    @return [#format_backtrace] the backtrace formatter

@overload backtrace_formatter=

    @param value [#format_backtrace] sets the backtrace formatter

### Public Instance Methods

add_should_and_should_not_to(*modules) click to toggle source

Adds `should` and `should_not` to the given classes or modules. This can be used to ensure `should` works properly on things like proxy objects (particular `Delegator`-subclassed objects on 1.8).

@param [Array<Module>] modules the list of classes or modules

    to add `should` and `should_not` to.

    # File lib/rspec/matchers/configuration.rb, line 62
    def add_should_and_should_not_to(*modules)
      modules.each do |mod|
        Expectations::Syntax.enable_should(mod)
      end
    end

backtrace_formatter() click to toggle source

    # File lib/rspec/matchers/configuration.rb, line 82
    def backtrace_formatter
      @backtrace_formatter ||= if defined?(::RSpec::Core::BacktraceFormatter)
        ::RSpec::Core::BacktraceFormatter
      else
        NullBacktraceFormatter
      end
    end

color?() click to toggle source

    # File lib/rspec/matchers/configuration.rb, line 45
    def color?
      ::RSpec.configuration.color_enabled?
    end

syntax() click to toggle source

The list of configured syntaxes. @return [Array<Symbol>] the list of configured syntaxes.

    # File lib/rspec/matchers/configuration.rb, line 35
    def syntax
      syntaxes = []
      syntaxes << :should if Expectations::Syntax.should_enabled?
      syntaxes << :expect if Expectations::Syntax.expect_enabled?
      syntaxes
    end

syntax=(values) click to toggle source

Configures the supported syntax. @param [Array<Symbol>, Symbol] values the syntaxes to enable @example

    RSpec.configure do |rspec|
      rspec.expect_with :rspec do |c|
        c.syntax = :should
        # or
        c.syntax = :expect
        # or
        c.syntax = [:should, :expect]
      end
    end

    # File lib/rspec/matchers/configuration.rb, line 19
    def syntax=(values)
      if Array(values).include?(:expect)
        Expectations::Syntax.enable_expect
      else
        Expectations::Syntax.disable_expect
      end

      if Array(values).include?(:should)
        Expectations::Syntax.enable_should
      else
        Expectations::Syntax.disable_should
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.