Class: XSpec::Notifier::ColoredDocumentation

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/xspec/notifiers.rb

Overview

Includes nicely formatted names and durations of each test in the output, with color.

Direct Known Subclasses

Documentation

Constant Summary collapse

VT100_COLORS =
{
  :black   => 30,
  :red     => 31,
  :green   => 32,
  :yellow  => 33,
  :blue    => 34,
  :magenta => 35,
  :cyan    => 36,
  :white   => 37
}

Instance Method Summary collapse

Methods included from Composable

#+

Constructor Details

#initialize(out = $stdout) ⇒ ColoredDocumentation

Returns a new instance of ColoredDocumentation.



236
237
238
239
240
241
# File 'lib/xspec/notifiers.rb', line 236

def initialize(out = $stdout)
  self.indent          = 2
  self.last_seen_names = []
  self.failed          = false
  self.out             = out
end

Instance Method Details

#color_code_for(color) ⇒ Object



218
219
220
# File 'lib/xspec/notifiers.rb', line 218

def color_code_for(color)
  VT100_COLORS.fetch(color)
end

#colorize(text, color) ⇒ Object



222
223
224
# File 'lib/xspec/notifiers.rb', line 222

def colorize(text, color)
  "\e[#{color_code_for(color)}m#{text}\e[0m"
end

#decorate(result) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'lib/xspec/notifiers.rb', line 226

def decorate(result)
  name = result.name
  out = if result.errors.any?
    colorize(append_failed(name), :red)
  else
    colorize(name , :green)
  end
  "%.3fs " % result.duration + out
end

#evaluate_finish(result) ⇒ Object



247
248
249
250
251
252
253
254
255
# File 'lib/xspec/notifiers.rb', line 247

def evaluate_finish(result)
  output_context_header! result.parents.map(&:name).compact

  spaces = ' ' * (last_seen_names.size * indent)

  self.failed ||= result.errors.any?

  out.puts "%s%s" % [spaces, decorate(result)]
end

#evaluate_start(*_) ⇒ Object



245
# File 'lib/xspec/notifiers.rb', line 245

def evaluate_start(*_); end

#run_finishObject



257
258
259
260
# File 'lib/xspec/notifiers.rb', line 257

def run_finish
  out.puts
  !failed
end

#run_startObject



243
# File 'lib/xspec/notifiers.rb', line 243

def run_start; end