Created
April 5, 2011 02:52
-
-
Save avivo/902937 to your computer and use it in GitHub Desktop.
Simple inline nonblocking testing without dependencies, and with readable stack traces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TESTING = true | |
def clean_backtrace(e) | |
puts "\t" + e.backtrace.reject{|t| t =~ /(assert_equal|[(\/]irb[.:\/)])/}.join("\n\t") | |
end | |
def assert_equal a, b | |
begin | |
raise if TESTING and a != b | |
rescue Exception => e | |
puts "*** Assertion failed: ***\n #{a} not equal to #{b}" | |
clean_backtrace(e) | |
end | |
end | |
#Put asserts in this block to only run them when testing is on | |
def test(&block) | |
begin | |
block.call if TESTING | |
rescue Exception => e | |
puts "*** Exception during tests: ***\n #{e.message}" | |
clean_backtrace(e) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment