Module: Fledgling

Defined in:
lib/fledgling.rb

Overview

This module provides a minimal testing library for testing better testing libraries.

Class Method Summary collapse

Class Method Details

.call(ostream, *tests) ⇒ Object

Runs tests, writes any failure information to the output stream, and returns a boolean indicating whether there were no failures.

This method sends, in order, a call message with no arguments and no block to each object in tests. If sending a call message raises an exception whose class is neither StandardError nor a descendant of StandardError, this method immediately raises that exception. If sending a call message raises a StandardError, this method interprets it as a failure. It sends a puts message to ostream with no block and these arguments (positional, in order): a string “FAILED TEST:”, the test converted to a string via to_s, a string “…ERROR:”, the exception’s class converted to a string via to_s, the exception converted to a string via to_s, the exception’s backtrace or an empty array if the exception signals that it has no backtrace, and an empty string. It ignores the object returned by the output stream and continues running tests. If sending a call message does not result in a raised exception, this method interprets it as a successful test. It ignores the object returned by the test and continues running tests. After it has run all the tests and handled any failures, this method returns false if there were failures, true otherwise. This method immediately raises any exception raised outside of a test.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fledgling.rb', line 29

def self.call ostream, *tests
  no_failures = true
  tests.each do |tst|
    begin
      tst.call
    rescue ::StandardError => e
      no_failures = false
      ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", e.class.to_s,
        e.to_s, e.backtrace || [], ""
    end
    # Always return nil so that an each that's been modified to be sensitive
    # to the block's return value can't behave differently based on the
    # objects returned by the tests and the output stream.
    nil
  end
  no_failures
end