Class: RSpec::Matchers::BuiltIn::RaiseError Private
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::RaiseError
- 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 Metrics/ClassLength
rubocop:disable Lint/RescueException
Constant Summary collapse
- UndefinedValue =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used as a sentinel value to be able to tell when the user did not pass an argument. We can't use
nil
for that because we need to warn whennil
is passed in a different way. It's an Object, not a Module, since Module's===
does not evaluate to true when compared to itself.Note; this is the default value supplied for expected_error_or_message, but because there are two method-calls involved, that default is actually supplied in the definition of the matcher method,
RSpec::Matchers#raise_error
Object.new.freeze
Instance Method Summary collapse
- #description ⇒ String private
- #failure_message ⇒ String private
- #failure_message_when_negated ⇒ String private
-
#initialize(expected_error_or_message, expected_message, &block) ⇒ RaiseError
constructor
private
A new instance of RaiseError.
-
#with_message(expected_message) ⇒ Object
Specifies the expected error message.
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
Constructor Details
#initialize(expected_error_or_message, expected_message, &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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 22 def initialize(, , &block) @block = block @actual_error = nil @warn_about_bare_error = UndefinedValue === @warn_about_nil_error = .nil? case when nil, UndefinedValue @expected_error = Exception @expected_message = when String, Regexp @expected_error = Exception @expected_message = else @expected_error = @expected_message = end end |
Instance Method Details
#description ⇒ String
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.
117 118 119 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 117 def description "raise #{expected_error}" end |
#failure_message ⇒ String
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.
105 106 107 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 105 def @eval_block ? : "expected #{expected_error}#{given_error}" end |
#failure_message_when_negated ⇒ String
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.
111 112 113 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 111 def "expected no #{expected_error}#{given_error}" end |
#with_message(expected_message) ⇒ Object
Specifies the expected error message.
43 44 45 46 47 48 |
# File 'lib/rspec/matchers/built_in/raise_error.rb', line 43 def () if @expected_message @warn_about_bare_error = false @expected_message = self end |