Class: Lookout::Expect::Exception

Inherits:
Object show all
Defined in:
lib/lookout-3.0/expect/exception.rb

Overview

Expect block of Lookout::Expected::Exceptions.

Instance Method Summary collapse

Instance Method Details

#callResults::Error, ...

Evaluates the expect block and checks the first raised Exception against the expected Exception. If no exception is raised, the actual result is checked against the expected value.

Returns:

  • (Results::Error)

    If the raised exception isn’t of the same class as that of the expected result

  • (Results::Success)

    If there are no differences between the actual result and the expected value

  • (Results::Failure)

    If there are differences between the actual result and the expected value



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lookout-3.0/expect/exception.rb', line 11

def call
  begin
    result = evaluate_block
  rescue Exception => actual
    exception = Lookout::Exception.new(actual)
    expected_class = expected.expected.class rescue Exception
    actual_class = exception.type
    return ((expected_class == actual_class) rescue false) ?
      check(actual) :
      Lookout::Results::Error.
        new(file,
            line,
            expected_class.to_lookout_expected.difference(actual_class).message,
            exception)
  end
  check(result)
rescue Exception => e
  Lookout::Results::Error.new(file, line, nil, Lookout::Exception.new(e))
end