Class: RSpec::Matchers::BuiltIn::RaiseError

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::new
- #==
- #description
- #does_not_match?
- #eval_block
- #failure_message_for_should
- #failure_message_for_should_not
- #matches?
- #verify_message

### 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::BuiltIn::RaiseError

### Public Class Methods

new(expected_error_or_message=Exception, expected_message=nil, &block) click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 5
    def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
      @block = block
      @actual_error = nil
      case expected_error_or_message
      when String, Regexp
        @expected_error, @expected_message = Exception, expected_error_or_message
      else
        @expected_error, @expected_message = expected_error_or_message, expected_message
      end
    end

### Public Instance Methods

==(given_proc, negative_expectation = false) click to toggle source
Alias for: matches?
description() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 85
    def description
      "raise #{expected_error}"
    end

does_not_match?(given_proc) click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 52
    def does_not_match?(given_proc)
      !matches?(given_proc, :negative_expectation)
    end

eval_block() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 56
    def eval_block
      @eval_block = true
      begin
        @block[@actual_error]
        @eval_block_passed = true
      rescue Exception => err
        @actual_error = err
      end
    end

failure_message_for_should() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 77
    def failure_message_for_should
      @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
    end

failure_message_for_should_not() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 81
    def failure_message_for_should_not
      "expected no #{expected_error}#{given_error}"
    end

matches?(given_proc, negative_expectation = false) click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 16
    def matches?(given_proc, negative_expectation = false)
      if negative_expectation && (expecting_specific_exception? || @expected_message)
        what_to_deprecate = if expecting_specific_exception? && @expected_message
                              "`expect { }.not_to raise_error(SpecificErrorClass, message)`"
                            elsif expecting_specific_exception?
                              "`expect { }.not_to raise_error(SpecificErrorClass)`"
                            elsif @expected_message
                              "`expect { }.not_to raise_error(message)`"
                            end
        RSpec.deprecate(what_to_deprecate, :replacement => "`expect { }.not_to raise_error()`")
      end
      @raised_expected_error = false
      @with_expected_message = false
      @eval_block = false
      @eval_block_passed = false
      unless given_proc.respond_to?(:call)
        ::Kernel.warn "`raise_error` was called with non-proc object #{given_proc.inspect}"
        return false
      end
      begin
        given_proc.call
      rescue Exception => @actual_error
        if @actual_error == @expected_error || @expected_error === @actual_error
          @raised_expected_error = true
          @with_expected_message = verify_message
        end
      end

      unless negative_expectation
        eval_block if @raised_expected_error && @with_expected_message && @block
      end
    ensure
      return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
    end

Also aliased as: ==
verify_message() click to toggle source

    # File lib/rspec/matchers/built_in/raise_error.rb, line 66
    def verify_message
      case @expected_message
      when nil
        true
      when Regexp
        @expected_message =~ @actual_error.message
      else
        @expected_message == @actual_error.message
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.