module Cucumber::Formatter::ANSIColor
This module allows to format cucumber related outputs using ANSI escape sequences.
For example, it provides a ‘passed` method which returns the string with the ANSI escape sequence to format it green per default.
To use this, include or extend it in your class.
Example:
require 'cucumber/formatter/ansicolor' class MyFormatter extend Cucumber::Term::ANSIColor def on_test_step_finished(event) $stdout.puts undefined(event.test_step) if event.result.undefined? $stdout.puts passed(event.test_step) if event.result.passed? end end
This module also allows the user to customize the format of cucumber outputs using environment variables.
For instance, if your shell has a black background and a green font (like the “Homebrew” settings for OS X’ Terminal.app), you may want to override passed steps to be white instead of green.
Example:
export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"
The colours that you can change are:
-
undefined- defaults toyellow -
pending- defaults toyellow -
pending_param- defaults toyellow,bold -
flaky- defaults toyellow -
flaky_param- defaults toyellow,bold -
failed- defaults tored -
failed_param- defaults tored,bold -
ambiguous- defaults tored -
abmiguous_param- defaults tored,bold -
passed- defaults togreen -
passed_param- defaults togreen,bold -
outline- defaults tocyan -
outline_param- defaults tocyan,bold -
skipped- defaults tocyan -
skipped_param- defaults tocyan,bold -
comment- defaults togrey -
tag- defaults tocyan
To see what colours and effects are available, just run this in your shell:
ruby -e "require 'rubygems'; require 'cucumber/term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"
Constants
- ALIASES
Public Class Methods
Source
# File lib/cucumber/formatter/ansicolor.rb, line 86 def self.apply_custom_colors(colors) colors.split(':').each do |pair| a = pair.split('=') ALIASES[a[0]] = a[1] end end
Apply the custom color scheme -> i.e. apply_custom_colors(‘passed=white’)
Public Instance Methods
Source
# File lib/cucumber/formatter/ansicolor.rb, line 117 def cukes(amount) ('(::) ' * amount).strip end
Source
# File lib/cucumber/formatter/ansicolor.rb, line 121 def green_cukes(amount) blink(green(cukes(amount))) end
Source
# File lib/cucumber/formatter/ansicolor.rb, line 125 def red_cukes(amount) blink(red(cukes(amount))) end
Source
# File lib/cucumber/formatter/ansicolor.rb, line 129 def yellow_cukes(amount) blink(yellow(cukes(amount))) end
Private Instance Methods
Source
# File lib/cucumber/formatter/ansicolor.rb, line 135 def apply_styles(styles, text = nil, &proc) styles.split(',').reverse.reduce(text) do |result, method_name| send(method_name, result, &proc) end end