class PrideFormatter
Constants
- ESC
stolen from minitest/pride
- NND
- PI_3
Attributes
output[R]
Public Class Methods
new(io)
click to toggle source
# File lib/rspec/pride.rb, line 14 def initialize io initialize_colors @output = io @index = 0 @size = @colors.size output.print "\n" end
Public Instance Methods
dump_summary(summary)
click to toggle source
# File lib/rspec/pride.rb, line 34 def dump_summary summary icing = 'Fabulous tests'.split(//).map { |x| rainbow x }.join summary_text = "#{summary.example_count} examples, " \ "#{summary.failure_count} failures, " \ "#{summary.pending_count} pending" formatted_summary = if summary.failure_count.to_i.zero? if summary.pending_count.zero? good summary_text else caution summary_text end else bad summary_text end output.print <<-TEXT #{icing} in #{summary.duration} #{formatted_summary} TEXT end
example_failed(example)
click to toggle source
# File lib/rspec/pride.rb, line 26 def example_failed example output.print failure end
example_passed(example)
click to toggle source
# File lib/rspec/pride.rb, line 22 def example_passed example output.print pass end
example_pending(example)
click to toggle source
# File lib/rspec/pride.rb, line 30 def example_pending example output.print pending end
Private Instance Methods
bad(str)
click to toggle source
# File lib/rspec/pride.rb, line 68 def bad(str) "#{ESC}32m#{ESC}31m#{str}#{NND}" end
caution(str)
click to toggle source
# File lib/rspec/pride.rb, line 72 def caution(str) "#{ESC}33m#{ESC}33m#{str}#{NND}" end
failure()
click to toggle source
# File lib/rspec/pride.rb, line 62 def failure; "\e[41m\e[37mF#{NND}"; end
good(str)
click to toggle source
# File lib/rspec/pride.rb, line 64 def good(str) "#{ESC}31m#{ESC}32m#{str}#{NND}" end
initialize_colors()
click to toggle source
Taken, wholesale, from minitest/pride
# File lib/rspec/pride.rb, line 81 def initialize_colors # walk red, green, and blue around a circle separated by equal thirds. # # To visualize, type this into wolfram-alpha: # # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3) # 6 has wide pretty gradients. 3 == lolcat, about half the width @colors = (0...(6 * 7)).map { |n| n *= 1.0 / 6 r = (3 * Math.sin(n ) + 3).to_i g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i # Then we take rgb and encode them in a single number using base 6. # For some mysterious reason, we add 16... to clear the bottom 4 bits? # Yes... they're ugly. 36 * r + 6 * g + b + 16 } end
pass()
click to toggle source
# File lib/rspec/pride.rb, line 60 def pass ; rainbow '.' ; end
pending()
click to toggle source
# File lib/rspec/pride.rb, line 61 def pending; "\e[40m\e[37mP#{NND}"; end
rainbow(string)
click to toggle source
# File lib/rspec/pride.rb, line 103 def rainbow string color = @colors[@index % @size] @index += 1 "#{ESC}38;5;#{color}m#{string}#{NND}" end