Class: Matchi::Matchers::RaiseException::Matcher

Inherits:
Object
  • Object
show all
Includes:
Matchi::MatchersBase
Defined in:
lib/matchi/matchers/raise_exception.rb

Overview

The matcher.

Instance Method Summary collapse

Methods included from Matchi::MatchersBase

#to_h, #to_s

Constructor Details

#initialize(expected) ⇒ Matcher

Initialize the matcher with a descendant of class Exception.

Examples:

Divided by 0 matcher.

Matchi::Matchers::RaiseException::Matcher.new(ZeroDivisionError)

Parameters:

  • expected (.exception)

    The class of the expected exception.



20
21
22
# File 'lib/matchi/matchers/raise_exception.rb', line 20

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

Is it raising NameError?

matcher = Matchi::Matchers::RaiseException::Matcher.new(NameError)
matcher.matches? { Boom } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



34
35
36
37
38
39
40
# File 'lib/matchi/matchers/raise_exception.rb', line 34

def matches?(*, **)
  yield
rescue @expected => _e
  true
else
  false
end