Exception: ThrowAssay
- Inherits:
-
ExecutionAssay
- Object
- Exception
- Assertion
- ExecutionAssay
- ThrowAssay
- Defined in:
- lib/assay/throw_assay.rb
Overview
Assertion for catching specific throws.
Constant Summary
Constants inherited from Assertion
Constants included from Assay::Assertable
Class Method Summary collapse
- .assert_message(symbol) ⇒ Object
-
.fail?(symbol = nil) ⇒ Boolean
Passes if the block does not throw given
symbol
. -
.pass?(symbol = nil) ⇒ Boolean
Passes if the block throws given symbol.
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(symbol) ⇒ Object
84 85 86 87 |
# File 'lib/assay/throw_assay.rb', line 84 def self.(symbol) s = symbol.inspect "throw #{s}" end |
.fail?(symbol = nil) ⇒ Boolean
Passes if the block does not throw given symbol
.
ThrowAssay.fail? :done do
throw :chimp
end
If no symbol is given then passes if nothing is thrown. But note that in ‘#refute!`, the symbol must be `nil` rather than not given.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/assay/throw_assay.rb', line 56 def self.fail?(symbol=nil) #:yield: if symbol pass = false catch(symbol) do begin yield rescue ArgumentError => err # 1.9 exception #msg += ", not #{err.message.split(/ /).last}" rescue NameError => err # 1.8 exception #msg += ", not #{err.name.inspect}" end pass = true end else pass = false begin yield pass = true rescue ArgumentError => error pass = true if /\Auncaught throw (.+)\z/ !~ error. end end pass end |
.pass?(symbol = nil) ⇒ Boolean
Passes if the block throws given symbol.
ThrowAssay.pass? :done do
throw :done
end
If no symbol is given than passes if any is thrown. But note that in ‘#assert!`, the symbol must be `nil` rather than not given.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/assay/throw_assay.rb', line 22 def self.pass?(symbol=nil) #:yield: pass = true if symbol catch(symbol) do begin yield rescue ArgumentError => err # 1.9 exception #msg += ", not #{err.message.split(/ /).last}" rescue NameError => err # 1.8 exception #msg += ", not #{err.name.inspect}" end pass = false end else begin yield pass = false rescue ArgumentError => error pass = false if /\Auncaught throw (.+)\z/ !~ error. end end pass end |