class Object

Public Instance Methods

assert(name, object1, object2) click to toggle source

Test the subject against it's expected return value. @example

assert('String test', '1'.class, String)
assert('Fixnum test', 1.class, Fixnum)

@param name [String] The name of the test, its used when reporting if it failed. @param object1 [Object] An expression to test. @param object2 [Object] The expected return value. @return [Bool] True if test passed.

# 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
Also aliased as: test
assert_block(name="") { || ... } click to toggle source

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. @example

assert_block('Foo tests') do
  foo = Foo.new

  puts('Foo test start')
  assert('Foo test #1', foo.get, true)
  assert('Foo test #2', foo.destroy, false)
  assert('Foo test #3', foo.destroyed?, true)
  puts('Foo test end')
end

@example The result you may get if $sep_switch is true.

--------- 
Foo tests
--------- 
Foo test start
Foo test end
---------

@param name [String] The of the group of the tests. @see report

# 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) { || ... } click to toggle source
report(str) click to toggle source

Prints a report of the tests above it. @param str [String] A string to be printed as the name of the report.

# 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
test(name, object1, object2)
Alias for: assert