Exception: RescueAssay

Inherits:
Assertion show all
Defined in:
lib/assay/rescue_assay.rb

Overview

Assert that a kind of exception class is rescued from the execution of a block.

Direct Known Subclasses

RaiseAssay

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Constants included from Assay::Assertable

Assay::Assertable::SIZE_LIMIT

Class Method Summary collapse

Methods inherited from Assertion

by_name, by_operator, inherited, register, subclasses

Methods included from Assay::Assertable

#[], #assert!, #assert_message, #assertive_name, #assertor, #fail?, #operator, #pass?, #refute!, #refute_message

Class Method Details

.assert_message(*exceptions) ⇒ Object



44
45
46
47
# File 'lib/assay/rescue_assay.rb', line 44

def self.assert_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "raise #{exp}" #, but was #{err} instead."
end

.fail?(*exceptions) ⇒ Boolean

Check negated assertion.

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/assay/rescue_assay.rb', line 28

def self.fail?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    true
  rescue Exception => e
    !exceptions.any? do |x|
      x === e
    end
  end
end

.pass?(*exceptions) ⇒ Boolean

Check assertion.

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/assay/rescue_assay.rb', line 13

def self.pass?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    false
  rescue Exception => e
    exceptions.any? do |x|
      x === e
    end
  end
end

.refute_message(*exceptions) ⇒ Object



50
51
52
53
# File 'lib/assay/rescue_assay.rb', line 50

def self.refute_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "! raise #{exp}" #, but was #{err} instead."
end