Class: RCheck::Assertions::Raises

Inherits:
Abstract
  • Object
show all
Defined in:
lib/rcheck/assertions.rb

Instance Attribute Summary

Attributes inherited from Abstract

#result

Instance Method Summary collapse

Methods inherited from Abstract

#debuggers, #inspect

Constructor Details

#initialize(expected, msg = nil, &blk) ⇒ Raises

Returns a new instance of Raises.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rcheck/assertions.rb', line 101

def initialize(expected, msg=nil, &blk)
  @expected = expected
  @expected_msg = msg
  @status = :fail
  begin
    blk.call
  rescue Exception => e
    @raised = e
    if @expected && e.is_a?(@expected) && (msg.nil? || e.message == msg)
      @status = :pass
    end
  end
  @status = :pass if @expected.nil? and @raised.nil?

  @result = Result.new(
    status:         @status,
    location:       caller(3),
    introspection:  @raised ? @raised.inspect : 'no errors',
    backtrace:      @status == :fail ? @raised.backtrace : nil)
end