Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First version of the cucumber-pride formatter.

(pretty ready for a v0.0.1 release, me thinks)
  • Loading branch information...
commit 9ffdded5c073ac93640a790f14143b2232465944 1 parent 7ff4404
@pvdb authored
Showing with 108 additions and 5 deletions.
  1. +23 −2 README.md
  2. +2 −0  cucumber-pride.gemspec
  3. +83 −3 lib/cucumber-pride.rb
View
25 README.md
@@ -1,6 +1,16 @@
-# Cucumber::Pride
+# cucumber-pride
-TODO: Write a gem description
+Take pride in your test output!
+
+Mimics the functionality of `minitest/pride` for Cucumber, in much the same way that `ferrous26/rspec-pride` does for RSpec2.
+
+## How to use cucumber-pride
+
+To use cucumber-pride, you need to call `cucumber` kind of like this:
+
+ cucumber --format Cucumber::Pride::Formatter
+
+Or put those options in your `config/cucumber.yml` file.
## Installation
@@ -20,6 +30,10 @@ Or install it yourself as:
TODO: Write usage instructions here
+## Acknowledgements
+
+* Main inspiration, and a fair amount of code, comes from the brilliant [`rspec-pride`](https://github.com/ferrous26/rspec-pride/) gem by [Mark Rade (ferrous26)](https://github.com/ferrous26).
+
## Contributing
1. Fork it
@@ -27,3 +41,10 @@ TODO: Write usage instructions here
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
+
+<a name="copyright"/>
+
+## Copyright
+
+Copyright (c) 2012 Peter Vandenberk. See LICENSE.txt for further details.
+
View
2  cucumber-pride.gemspec
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
gem.name = "cucumber-pride"
gem.require_paths = ["lib"]
gem.version = Cucumber::Pride::VERSION
+
+ gem.add_dependency 'cucumber', ['~> 1.1.1']
end
View
86 lib/cucumber-pride.rb
@@ -1,7 +1,87 @@
require "cucumber-pride/version"
+require 'rubygems'
+require 'cucumber/formatter/progress'
+
module Cucumber
module Pride
- # Your code goes here...
- end
-end
+ class Formatter < Cucumber::Formatter::Progress
+
+ def initialize(step_mother, io, options)
+ super
+ initialize_colors
+ @index = 0
+ @size = @colors.size
+ end
+
+ private
+
+ def progress(status)
+ char = CHARS[status]
+ char = rainbow(char) if char == '.'
+ @io.print(format_string(char, status))
+ @io.flush
+ end
+
+ def dump_count(count, what, state=nil)
+ super.split(//).map { |x| rainbow x }.join
+ end
+
+ #
+ # what follows: shamelessly borrowed from https://github.com/ferrous26/rspec-pride
+ #
+
+ ESC = "\e["
+ NND = "#{ESC}0m"
+
+ if ENV['TERM'] =~ /^xterm(-256color)?$/
+
+ PI_3 = Math::PI / 3
+
+ # Taken, wholesale, from minitest/pride
+ 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
+
+ def rainbow string
+ color = @colors[@index % @size]
+ @index += 1
+ "#{ESC}38;5;#{color}m#{string}#{NND}"
+ end
+
+ else # Old Low-Res Pride
+
+ def initialize_colors
+ @colors = (31..36).to_a
+ end
+
+ def rainbow string
+ # string = '*' if string == '.'
+ color = @colors[@index % @size]
+ @index += 1
+ "#{ESC}#{color}m#{string}#{NND}"
+ end
+
+ end # if ENV['TERM'] =~ /^xterm(-256color)?$/
+
+ end # class Formatter
+ end # module Pride
+end # module Cucumber
Please sign in to comment.
Something went wrong with that request. Please try again.