Top Level Namespace
Defined Under Namespace
Classes: String
Instance Method Summary collapse
-
#assert(name, object1, object2) ⇒ Bool
(also: #test)
Test the subject against it’s expected return value.
-
#assert_block(name = "") ⇒ Object
Provides a block for tests that needs to be grouped togther.
- #print_bounds(str, plus = 0) ⇒ Object
-
#report(str) ⇒ Object
Prints a report of the tests above it.
Instance Method Details
#assert(name, object1, object2) ⇒ Bool Also known as: test
Test the subject against it’s expected return value.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_test.rb', line 35 def assert(name, object1, object2) ret = object1.eql?(object2) if ret $ok += 1 else $fails += 1 $fail_names.push(name) end $total += 1 ret end |
#assert_block(name = "") ⇒ Object
Provides a block for tests that needs to be grouped togther. When the tests report is printed if the global variable $sep_switch is set to true(it is true by default), then bounddires are printed around the test, with the name of the test printed prominently.
87 88 89 90 91 92 93 |
# File 'lib/ruby_test.rb', line 87 def assert_block(name="") if $sep_switch print_bounds(name) { yield } if $sep_switch else yield end end |
#print_bounds(str, plus = 0) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_test.rb', line 50 def print_bounds(str, plus=0) sep_str = '-' str_size = str.size + plus str_size.times { print(sep_str.color_mode(:normal)) } puts(' ') # Printing newlines puts(str.color_mode(:normal)) str_size.times { print(sep_str.color_mode(:normal)) } puts(' ') yield str_size.times { print(sep_str.color_mode(:normal)) } puts(' ') end |
#report(str) ⇒ Object
Prints a report of the tests above it.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ruby_test.rb', line 97 def report(str) print_bounds("Summary for: #{str}") do $fail_names.each { |n| puts("Failed test => #{n}".color_mode(:fail)) } puts("Total: #{$total}".color_mode(:normal)) puts("Ok: #{$ok}".color_mode(:ok)) puts("Fails: #{$fails}".color_mode(:fail)) end $total = 0 $ok = 0 $fails = 0 end |