Class: MiniTest::Colorize
- Inherits:
-
Object
- Object
- MiniTest::Colorize
- Defined in:
- lib/minitest/colorize.rb,
lib/minitest/colorize/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(stream = $stdout) ⇒ Colorize
constructor
A new instance of Colorize.
- #method_missing(method, *args, &block) ⇒ Object
- #print(string = nil) ⇒ Object
- #puts(string = nil) ⇒ Object
Constructor Details
#initialize(stream = $stdout) ⇒ Colorize
Returns a new instance of Colorize.
8 9 10 11 12 |
# File 'lib/minitest/colorize.rb', line 8 def initialize(stream = $stdout) self.stream = stream.tap do |stream| stream.sync = true if stream.respond_to?(:sync=) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
52 53 54 |
# File 'lib/minitest/colorize.rb', line 52 def method_missing(method, *args, &block) stream.send(method, *args, &block) end |
Instance Attribute Details
#stream ⇒ Object
Returns the value of attribute stream.
6 7 8 |
# File 'lib/minitest/colorize.rb', line 6 def stream @stream end |
Instance Method Details
#print(string = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/minitest/colorize.rb', line 14 def print(string = nil) return stream.print if string.nil? case string when 'E', 'F' stream.print red(string) when 'S' stream.print yellow(string) when '.' stream.print green(string) else stream.print string end unless report.empty? stream.puts stream.puts stream.puts report.shift stream.puts end end |
#puts(string = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/minitest/colorize.rb', line 36 def puts(string = nil) return stream.puts if string.nil? if string =~ /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips/ if $3 != '0' || $4 != '0' stream.puts red(string) elsif $5 != '0' stream.puts yellow(string) else stream.puts green(string) end else stream.puts string end end |