Module: CodeAssertions
- Defined in:
- lib/code-assertions.rb
Defined Under Namespace
Classes: CodeAssertionFailed
Constant Summary
collapse
- @@assertions_check =
true
Instance Method Summary
collapse
Instance Method Details
#assert(message = nil, &block) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/code-assertions.rb', line 13
def assert(message=nil, &block)
return unless @@assertions_check
unless block
warn "Empty assertion passed."
return
end
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
raise CodeAssertionFailed, message 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
23
24
25
26
27
28
29
30
31
|
# File 'lib/code-assertions.rb', line 23
def soft_assert(message=nil, &block)
return unless @@assertions_check
unless block
warn "Empty assertion passed."
return
end
message = "Assertion failed: " + block.to_source[6...-1].strip unless message
warn message unless block.call
end
|