Module: Sunlight
- Defined in:
- lib/sunlight.rb
Overview
This module provides a minimal testing library for testing better testing libraries.
Class Method Summary collapse
-
.call(ostream, *tests) ⇒ Object
Runs tests, writes any failure information to the output stream, and returns a boolean indicating whether there were no failures.
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 string returned when a to_s message is sent to the test; a string “…ERROR:”; a string combining the class, string representation (via to_s), and backtrace of the exception; 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sunlight.rb', line 28 def self.call ostream, *tests no_failures = true tests.each do |tst| begin tst.call rescue ::StandardError => e no_failures = false # Like IO#puts, separate lines with \n rather than $\. estr = ["#{e.class}: #{e}"].concat(e.backtrace || []).join "\n" ostream.puts "FAILED TEST:", tst.to_s, "...ERROR:", estr, "" end nil end no_failures end |