Class: RSpec::Matchers::BuiltIn::ThrowSymbol

### Home Classes Methods

### In Files

- lib/rspec/matchers/built_in/throw_symbol.rb

### Parent

Object

### Methods

- ::new
- #description
- #does_not_match?
- #expects_call_stack_jump?
- #failure_message
- #failure_message_when_negated
- #matches?
- #supports_block_expectations?

### Included Modules

- RSpec::Matchers::Composable

### 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::Matchers::BuiltIn::ThrowSymbol

@api private Provides the implementation for `throw_symbol`. Not intended to be instantiated directly.

### Public Class Methods

new(expected_symbol=nil, expected_arg=nil) click to toggle source

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 10
    def initialize(expected_symbol=nil, expected_arg=nil)
      @expected_symbol = expected_symbol
      @expected_arg = expected_arg
      @caught_symbol = @caught_arg = nil
    end

### Public Instance Methods

description() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 86
    def description
      "throw #{expected}"
    end

does_not_match?(given_proc) click to toggle source

rubocop:enable MethodLength

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 68
    def does_not_match?(given_proc)
      !matches?(given_proc) && Proc === given_proc
    end

expects_call_stack_jump?() click to toggle source

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 97
    def expects_call_stack_jump?
      true
    end

failure_message() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 74
    def failure_message
      "expected #{expected} to be thrown, #{actual_result}"
    end

failure_message_when_negated() click to toggle source

@api private @return [String]

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 80
    def failure_message_when_negated
      "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, #{actual_result}"
    end

matches?(given_proc) click to toggle source

rubocop:disable MethodLength @private

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 18
    def matches?(given_proc)
      @block = given_proc
      return false unless Proc === given_proc

      begin
        if @expected_symbol.nil?
          given_proc.call
        else
          @caught_arg = catch :proc_did_not_throw_anything do
            catch @expected_symbol do
              given_proc.call
              throw :proc_did_not_throw_anything, :nothing_thrown
            end
          end

          if @caught_arg == :nothing_thrown
            @caught_arg = nil
          else
            @caught_symbol = @expected_symbol
          end
        end

        # Ruby 1.8 uses NameError with `symbol'
        # Ruby 1.9 uses ArgumentError with :symbol
      rescue NameError, ArgumentError => e
        unless (match_data = e.message.match(/uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/))
          other_exception = e
          raise
        end
        @caught_symbol = match_data.captures[1].to_sym
      rescue => other_exception
        raise
      ensure
        # rubocop:disable EnsureReturn
        unless other_exception
          if @expected_symbol.nil?
            return !!@caught_symbol
          else
            if @expected_arg.nil?
              return @caught_symbol == @expected_symbol
            else
              return (@caught_symbol == @expected_symbol) && values_match?(@expected_arg, @caught_arg)
            end
          end
        end
        # rubocop:enable EnsureReturn
      end
    end

supports_block_expectations?() click to toggle source

@api private Indicates this matcher matches against a block. @return [True]

    # File lib/rspec/matchers/built_in/throw_symbol.rb, line 93
    def supports_block_expectations?
      true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.