Module: Cucumber::Formatter::ANSIColor

Includes:
Term::ANSIColor
Included in:
Console
Defined in:
lib/cucumber/formatter/ansicolor.rb

Overview

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 to yellow

  • pending - defaults to yellow

  • pending_param - defaults to yellow,bold

  • flaky - defaults to yellow

  • flaky_param - defaults to yellow,bold

  • failed - defaults to red

  • failed_param - defaults to red,bold

  • passed - defaults to green

  • passed_param - defaults to green,bold

  • outline - defaults to cyan

  • outline_param - defaults to cyan,bold

  • skipped - defaults to cyan

  • skipped_param - defaults to cyan,bold

  • comment - defaults to grey

  • tag - defaults to cyan

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"

Constant Summary collapse

ALIASES =

:stopdoc:

Hash.new do |h, k|
  next unless k.to_s =~ /(.*)_param/

  "#{h[Regexp.last_match(1)]},bold"
end.merge(
  'undefined' => 'yellow',
  'pending'   => 'yellow',
  'flaky'     => 'yellow',
  'failed'    => 'red',
  'passed'    => 'green',
  'outline'   => 'cyan',
  'skipped'   => 'cyan',
  'comment'   => 'grey',
  'tag'       => 'cyan'
)

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Term::ANSIColor

#attributes, included, #uncolored

Class Method Details

.apply_custom_colors(colors) ⇒ Object

Apply the custom color scheme

example:

apply_custom_colors('passed=white')


89
90
91
92
93
94
# File 'lib/cucumber/formatter/ansicolor.rb', line 89

def self.apply_custom_colors(colors)
  colors.split(':').each do |pair|
    a = pair.split('=')
    ALIASES[a[0]] = a[1]
  end
end

Instance Method Details

#cukes(n) ⇒ Object

:stopdoc:



121
122
123
# File 'lib/cucumber/formatter/ansicolor.rb', line 121

def cukes(n)
  ('(::) ' * n).strip
end

#green_cukes(n) ⇒ Object



125
126
127
# File 'lib/cucumber/formatter/ansicolor.rb', line 125

def green_cukes(n)
  blink(green(cukes(n)))
end

#red_cukes(n) ⇒ Object



129
130
131
# File 'lib/cucumber/formatter/ansicolor.rb', line 129

def red_cukes(n)
  blink(red(cukes(n)))
end

#yellow_cukes(n) ⇒ Object



133
134
135
# File 'lib/cucumber/formatter/ansicolor.rb', line 133

def yellow_cukes(n)
  blink(yellow(cukes(n)))
end