/
documentation_formatter.rb
71 lines (53 loc) · 1.71 KB
/
documentation_formatter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'rspec/core/formatters/base_text_formatter'
module RSpec
module Core
module Formatters
class DocumentationFormatter < BaseTextFormatter
def initialize(output)
super(output)
@group_level = 0
end
def example_group_started(example_group)
super(example_group)
output.puts if @group_level == 0
output.puts "#{current_indentation}#{example_group.description}"
@group_level += 1
end
def example_group_finished(example_group)
@group_level -= 1
end
def example_passed(example)
super(example)
output.puts passed_output(example)
end
def example_pending(example)
super(example)
output.puts pending_output(example, example.execution_result[:pending_message])
end
def example_failed(example)
super(example)
output.puts failure_output(example, example.execution_result[:exception])
end
def failure_output(example, exception)
red("#{current_indentation}#{example.description} (FAILED - #{next_failure_index})")
end
def next_failure_index
@next_failure_index ||= 0
@next_failure_index += 1
end
def passed_output(example)
green("#{current_indentation}#{example.description}")
end
def pending_output(example, message)
yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
end
def current_indentation
' ' * @group_level
end
def example_group_chain
example_group.ancestors.reverse
end
end
end
end
end