Module: CodeAssertions
- Defined in:
- lib/code-assertions.rb
Constant Summary collapse
- CodeAssertionFailed =
Class.new(Exception)
- @@assertions_check =
true
Instance Method Summary collapse
- #assert(message = nil, &block) ⇒ Object
- #assertions_off ⇒ Object (also: #do_not_assert)
- #soft_assert(message = nil, &block) ⇒ Object
Instance Method Details
#assert(message = nil, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code-assertions.rb', line 13 def assert(=nil, &block) return unless @@assertions_check unless block warn "Empty assertion passed." return end begin = "Assertion failed: " + block.to_source[6...-1].strip unless rescue Exception = "Assertion failed: <no message provided>" end raise CodeAssertionFailed, unless block.call end |
#assertions_off ⇒ Object Also known as: do_not_assert
7 8 9 |
# File 'lib/code-assertions.rb', line 7 def assertions_off @@assertions_check = false end |
#soft_assert(message = nil, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/code-assertions.rb', line 28 def soft_assert(=nil, &block) return unless @@assertions_check unless block warn "Empty assertion passed." return end begin = "Assertion failed: " + block.to_source[6...-1].strip unless rescue Exception = "Assertion failed: <no message provided>" end warn unless block.call end |