Exception: RescueAssay
- 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
Constant Summary
Constants inherited from Assertion
Constants included from Assay::Assertable
Class Method Summary collapse
- .assert_message(*exceptions) ⇒ Object
-
.fail?(*exceptions) ⇒ Boolean
Check negated assertion.
-
.pass?(*exceptions) ⇒ Boolean
Check assertion.
- .refute_message(*exceptions) ⇒ Object
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.(*exceptions) exp = exceptions.map{ |e| e.inspect }.join(' or ') "raise #{exp}" #, but was #{err} instead." end |
.fail?(*exceptions) ⇒ Boolean
Check negated assertion.
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.
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.(*exceptions) exp = exceptions.map{ |e| e.inspect }.join(' or ') "! raise #{exp}" #, but was #{err} instead." end |