Class: Specifier::Formatter::Documentation

Inherits:
Base
  • Object
show all
Defined in:
lib/specifier/formatter/documentation.rb

Overview

A custom defintion for formatting the specifier results.

Usage:

formatter = Specifier::Formatter::Documentation.new
formatter.context(context) do
  formatter.record(example, result)
end
formatter.summarize

Constant Summary collapse

INDENTATION =
'  '.freeze
NAME =
'documentation'.freeze
PASS =
'[PASS]'.freeze
FAIL =
'[FAIL]'.freeze

Instance Method Summary collapse

Methods inherited from Base

#summarize

Constructor Details

#initialize(logger) ⇒ Documentation

Returns a new instance of Documentation.



22
23
24
25
# File 'lib/specifier/formatter/documentation.rb', line 22

def initialize(logger)
  super
  @indentation = 0
end

Instance Method Details

#context(context) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/specifier/formatter/documentation.rb', line 39

def context(context)
  @logger.log(indent(context.description))

  @indentation = @indentation.next
  super
  @indentation = @indentation.pred
end

#record(example, result) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/specifier/formatter/documentation.rb', line 27

def record(example, result)
  super

  message =
    case result.status
    when :pass then Colorizer.passed(indent("#{PASS} #{example.description}"))
    when :fail then Colorizer.failed(indent("#{FAIL} #{example.description}"))
    end

  @logger.log(message)
end