Class: RSpec::Matchers::BuiltIn::RaiseError Private
- Includes:
- Composable
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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 when `nil` 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.
Object.new.freeze
Instance Method Summary collapse
- #description ⇒ String private
- #does_not_match?(given_proc) ⇒ Boolean private
- #expects_call_stack_jump? ⇒ Boolean 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.
-
#matches?(given_proc, negative_expectation = false, &block) ⇒ Boolean
private
rubocop:disable Metrics/MethodLength.
- #supports_block_expectations? ⇒ Boolean private
- #supports_value_expectations? ⇒ Boolean private
-
#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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 18 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 @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.
113 114 115 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 113 def description "raise #{expected_error}" end |
#does_not_match?(given_proc) ⇒ 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.
79 80 81 82 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 79 def does_not_match?(given_proc) warn_for_negative_false_positives! !matches?(given_proc, :negative_expectation) && Proc === given_proc 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.
95 96 97 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 95 def expects_call_stack_jump? true 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.
101 102 103 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 101 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.
107 108 109 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 107 def "expected no #{expected_error}#{given_error}" end |
#matches?(given_proc, negative_expectation = false, &block) ⇒ 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.
rubocop:disable Metrics/MethodLength
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 48 def matches?(given_proc, negative_expectation=false, &block) @given_proc = given_proc @block ||= block @raised_expected_error = false @with_expected_message = false @eval_block = false @eval_block_passed = false return false unless Proc === given_proc begin given_proc.call rescue Exception => @actual_error if values_match?(@expected_error, @actual_error) || values_match?(@expected_error, ) @raised_expected_error = true @with_expected_message = end end unless negative_expectation if warn_about_nil_error! if warn_about_nil_error? eval_block if ready_to_eval_block? end expectation_matched? end |
#supports_block_expectations? ⇒ 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.
85 86 87 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 85 def supports_block_expectations? true end |
#supports_value_expectations? ⇒ 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.
90 91 92 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 90 def supports_value_expectations? false end |
#with_message(expected_message) ⇒ Object
Specifies the expected error message.
39 40 41 42 43 44 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/raise_error.rb', line 39 def () if @expected_message @warn_about_bare_error = false @expected_message = self end |