Class: Huh
- Inherits:
-
Object
- Object
- Huh
- Defined in:
- lib/huh.rb
Defined Under Namespace
Classes: Failure
Class Method Summary collapse
- .assert(truth) ⇒ Object
-
.assert_equal(a, b) ⇒ Object
true == true..yes.
-
.assert_nil(a) ⇒ Object
true == true..yes.
-
.finish! ⇒ Object
spit out info.
-
.flunk ⇒ Object
always fails.
-
.oz(v) ⇒ Object
value or_zero.
- .test(name, &block) ⇒ Object
Class Method Details
.assert(truth) ⇒ Object
13 14 15 |
# File 'lib/huh.rb', line 13 def self.assert(truth) !!truth ? (@a = oz(@a) + 1) : (@f = oz(@f) + 1; raise Failure) end |
.assert_equal(a, b) ⇒ Object
true == true..yes
18 |
# File 'lib/huh.rb', line 18 def self.assert_equal(a,b); assert(a == b); end |
.assert_nil(a) ⇒ Object
true == true..yes
19 |
# File 'lib/huh.rb', line 19 def self.assert_nil(a); assert(a.nil?); end |
.finish! ⇒ Object
spit out info
20 |
# File 'lib/huh.rb', line 20 def self.finish!;puts "\n#{oz(@t)} tests, #{oz(@a)} assertions, #{oz(@f)} failures. #{(((oz(@t)-oz(@f)).to_f/@t.to_f)*100).to_i}% passing tests"; end |
.flunk ⇒ Object
always fails
17 |
# File 'lib/huh.rb', line 17 def self.flunk; assert(false); end |
.oz(v) ⇒ Object
value or_zero
16 |
# File 'lib/huh.rb', line 16 def self.oz(v); v or 0; end |
.test(name, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/huh.rb', line 3 def self.test(name, &block) @t = oz(@t) + 1 begin yield rescue Failure => e print "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n" else print "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n" end end |