Class: Easytest::Matcher::Raise

Inherits:
Base
  • Object
show all
Defined in:
lib/easytest/matcher/raise.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#actual, #expected, #negate

Instance Method Summary collapse

Methods inherited from Base

#match!

Constructor Details

#initialize(actual:, expected:, negate:, with_message:) ⇒ Raise

Returns a new instance of Raise.



6
7
8
9
# File 'lib/easytest/matcher/raise.rb', line 6

def initialize(actual:, expected:, negate:, with_message:)
  super(actual: actual, expected: expected, negate: negate)
  @with_message = with_message
end

Instance Attribute Details

#with_messageObject (readonly)

Returns the value of attribute with_message.



4
5
6
# File 'lib/easytest/matcher/raise.rb', line 4

def with_message
  @with_message
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/easytest/matcher/raise.rb', line 11

def match?
  begin
    actual.call
    false
  rescue => error
    @raised_error = error
    match_error?(error)
  end
end

#messageObject



25
26
27
# File 'lib/easytest/matcher/raise.rb', line 25

def message
  "raise"
end

#raise_match_errorObject

Raises:



21
22
23
# File 'lib/easytest/matcher/raise.rb', line 21

def raise_match_error
  raise MatchError.new(message: build_error_message, actual: @raised_error, expected: expected)
end