lib/nanotest.rb in nanotest-0.9.2 vs lib/nanotest.rb in nanotest-0.9.3
- old
+ new
@@ -1,18 +1,22 @@
-module NanoTest
+module Nanotest
extend self
- FAILURES = []
+ @@failures, @@dots = [], []
- def assert(msg="assertion failed", file=nil, line=nil, &block)
+ def assert(msg=nil, file=nil, line=nil, &block)
unless block.call
file ||= caller.first.split(':')[0]
line ||= caller.first.split(':')[1]
- FAILURES << "(%s:%0.3d) %s" % [file,line,msg]
- print 'F'
+ @@failures << "(%s:%0.3d) %s" % [file, line, msg || "assertion failed"]
+ @@dots << 'F'
else
- print '.'
+ @@dots << '.'
end
end
- at_exit { puts; FAILURES.each {|f| puts f } }
+ def self.results #:nodoc:
+ @@dots.join + "\n" + @@failures.join("\n")
+ end
+
+ at_exit { puts results unless results.strip.empty? }
end