Browse files

Pride example

  • Loading branch information...
1 parent 609f50a commit a442b947d71ebf826f2ae4dd181398d721dda289 @iain committed Jul 22, 2012
Showing with 56 additions and 0 deletions.
  1. +5 −0 Rakefile
  2. +1 −0 cucumber.yml
  3. +37 −0 examples/pride.rb
  4. +13 −0 lib/scripted/formatters/blank.rb
View
5 Rakefile
@@ -31,4 +31,9 @@ namespace :examples do
config_file "examples/important.rb"
end
+ desc "Runs the pride example"
+ Scripted::RakeTask.new(:pride) do
+ config_file "examples/pride.rb"
+ end
+
end
View
1 cucumber.yml
@@ -1,2 +1,3 @@
default: --format Fivemat --strict --tags ~@wip --color
wip: --format pretty --wip --tags @wip --color
+no-color: --format Fivemat --strict --tags ~@wip
View
37 examples/pride.rb
@@ -0,0 +1,37 @@
+# Taken from Minitest's Pride formatter
+# Meant as example of custom formatters
+
+require "scripted/formatters/blank"
+
+class Pride < Scripted::Formatters::Blank
+
+ PI_3 = Math::PI / 3
+
+ def initialize(*)
+ super
+ @index = 0
+ @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
+ 36 * r + 6 * g + b + 16
+ }
+ @size = @colors.size
+ end
+
+ def each_char(char, command)
+ print pride(char)
+ end
+
+ def pride(string)
+ color = @colors[@index % @size]
+ @index += 1
+ "\e[38;5;#{color}m#{string}\e[0m"
+ end
+end
+
+formatter Pride
+
+run "rspec --no-color"
+run "cucumber -p no-color"
View
13 lib/scripted/formatters/blank.rb
@@ -4,32 +4,45 @@ class Blank
attr_reader :raw_out, :configuration
+ # Called whn Scripted starts.
+ # If you override this, don't forget to call `super`.
def initialize(out, configuration)
@raw_out = out || $stderr
@configuration = configuration
end
+ # Called when the commands to be run have been selected
+ # No command has yet been run
def start(commands, runner)
end
+ # Called after all commands have been run.
def stop(commands, runner)
end
+ # Called whenever a command has failed.
def exception(command, exception)
end
+ # Called whenever a command has been run.
def done(command)
end
+ # Called when an important command has failed.
def halted(command)
end
+ # Called just before a command starts running
def execute(command)
end
+ # Called just before scripted exits. Useful for closing streams and
+ # closing connections.
def close
end
+ # Called for each character that went to stdout or stderr.
+ # Doesn't include output of other formatters.
def each_char(output, command)
end

0 comments on commit a442b94

Please sign in to comment.