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

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/rspec/matchers/built_in/raise_error.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation for raise_error. Not intended to be instantiated directly. rubocop:disable ClassLength

Instance Method Summary collapse

Methods included from Composable

#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, #values_match?

Constructor Details

#initialize(expected_error_or_message = nil, expected_message = nil, &block) ⇒ RaiseError

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RaiseError



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 11

def initialize(expected_error_or_message=nil, expected_message=nil, &block)
  @block = block
  @actual_error = nil
  @warn_about_bare_error = warn_about_potential_false_positives? && expected_error_or_message.nil?

  case expected_error_or_message
  when nil
    @expected_error, @expected_message = Exception, expected_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

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


92
93
94
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 92

def description
  "raise #{expected_error}"
end

#expects_call_stack_jump?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


74
75
76
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 74

def expects_call_stack_jump?
  true
end

#failure_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


80
81
82
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 80

def failure_message
  @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
end

#failure_message_when_negatedString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


86
87
88
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 86

def failure_message_when_negated
  "expected no #{expected_error}#{given_error}"
end

#with_message(expected_message) ⇒ Object

Specifies the expected error message.



28
29
30
31
32
33
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 28

def with_message(expected_message)
  raise_message_already_set if @expected_message
  @warn_about_bare_error = false
  @expected_message = expected_message
  self
end