Module: Dots

Extended by:
Dots
Includes:
Enumerable
Included in:
Dots
Defined in:
lib/dots.rb

Overview

Dots makes dots.

Defined Under Namespace

Classes: InvalidDot

Constant Summary collapse

VERSION =
"0.0.2"
@@dots =

– How dots appear. ++

{ "." => ".", "F" => "F", "E" => "E" }

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Access how a dot should appear.

Raises:



20
21
22
23
24
# File 'lib/dots.rb', line 20

def [](key)
  raise InvalidDot unless @@dots.keys.include? key.to_s
  dot = @@dots[key.to_s]
  dot.respond_to?(:call) ? dot.call : dot
end

#[]=(key, value) ⇒ Object

Configure how dots appear. For red and green:

Dots["."] = "\e[32m.\e[0m"
Dots["F"] = "\e[31mF\e[0m"
Dots["E"] = "\e[31mE\e[0m"

Or, just require "dots/redgreen".

For a random rainbow, require "dots/rainbow", or use a procedure:

Dots["."] = Proc.new { \e[%dm.\e[0m" % [rand(10) + 30] }

Raises:



37
38
39
40
# File 'lib/dots.rb', line 37

def []=(key, value)
  raise InvalidDot unless @@dots.keys.include? key.to_s
  @@dots[key.to_s] = value
end

#report(exceptions, passed = 0, start = nil, io = $stdout) ⇒ Object

Formats reports for each_with_dots.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/dots.rb', line 135

def report(exceptions, passed = 0, start = nil, io = $stdout)
  failed = erred = 0

  io.puts
  io.puts "Finished in #{Time.now - start} seconds." unless start.nil?
  exceptions.each_with_index do |(o, e), i|
    io.puts
    if e.is_a? RuntimeError
      failed += 1
      io.puts "%3d) Failure" % [i + 1]
      io.puts "#{e.message} " unless e.message.empty?
      io.puts "with <#{o.inspect}>"
      io.puts "[#{e.backtrace.first[/.+\d+/]}]"
    else
      erred += 1
      io.puts "%3d) Error" % [i + 1]
      io.puts "#{e.class.name}: #{e.message}"
      io.puts "with <#{o.inspect}>"
      io.puts e.backtrace.select { |l| l !~ /dots.rb/ }.map { |l| "\t#{l}" }
    end
  end
  io.puts
  io.puts summary(passed, failed, erred)
end