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

Instance Method Summary collapse

Methods inherited from Base

#summarize

Constructor Details

#initialize(logger) ⇒ Documentation

Returns a new instance of Documentation.



20
21
22
23
# File 'lib/specifier/formatter/documentation.rb', line 20

def initialize(logger)
  super
  @indentation = 0
end

Instance Method Details

#context(context) ⇒ Object



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

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

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

#record(example, result) ⇒ Object



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

def record(example, result)
  super

  message =
    case result.status
    when :pass then Colorizer.passed(indent(example.description))
    when :fail then Colorizer.failed(indent(example.description))
    end

  @logger.log(message)
end