Class: Matchi::RaiseException
- Inherits:
- BasicObject
- Defined in:
- lib/matchi/raise_exception.rb
Overview
**Expecting errors** matcher.
Instance Method Summary collapse
-
#initialize(expected) ⇒ RaiseException
constructor
Initialize the matcher with a descendant of class Exception.
-
#matches? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
-
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the matcher and a value corresponding to its initialize parameters.
-
#to_s ⇒ String
Returns a string representing the matcher.
Constructor Details
#initialize(expected) ⇒ RaiseException
Initialize the matcher with a descendant of class Exception.
10 11 12 |
# File 'lib/matchi/raise_exception.rb', line 10 def initialize(expected) @expected = expected end |
Instance Method Details
#matches? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
23 24 25 26 27 28 29 |
# File 'lib/matchi/raise_exception.rb', line 23 def matches? yield rescue @expected true else false end |
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the
matcher and a value corresponding to its initialize parameters.
50 51 52 |
# File 'lib/matchi/raise_exception.rb', line 50 def to_h { RaiseException: [@expected] } end |
#to_s ⇒ String
Returns a string representing the matcher.
38 39 40 |
# File 'lib/matchi/raise_exception.rb', line 38 def to_s "raise_exception #{@expected.inspect}" end |