/
documentation_formatter_spec.rb
88 lines (70 loc) · 2.6 KB
/
documentation_formatter_spec.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'spec_helper'
require 'rspec/core/formatters/documentation_formatter'
module RSpec::Core::Formatters
describe DocumentationFormatter do
it "numbers the failures" do
examples = [
double("example 1",
:description => "first example",
:execution_result => {:status => 'failed', :exception => Exception.new }
),
double("example 2",
:description => "second example",
:execution_result => {:status => 'failed', :exception => Exception.new }
)
]
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
examples.each {|e| formatter.example_failed(e) }
expect(output.string).to match(/first example \(FAILED - 1\)/m)
expect(output.string).to match(/second example \(FAILED - 2\)/m)
end
it "represents nested group using hierarchy tree" do
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
group = RSpec::Core::ExampleGroup.describe("root")
context1 = group.describe("context 1")
context1.example("nested example 1.1"){}
context1.example("nested example 1.2"){}
context11 = context1.describe("context 1.1")
context11.example("nested example 1.1.1"){}
context11.example("nested example 1.1.2"){}
context2 = group.describe("context 2")
context2.example("nested example 2.1"){}
context2.example("nested example 2.2"){}
group.run(RSpec::Core::Reporter.new(RSpec.configuration, formatter))
expect(output.string).to eql("
root
context 1
nested example 1.1
nested example 1.2
context 1.1
nested example 1.1.1
nested example 1.1.2
context 2
nested example 2.1
nested example 2.2
")
end
it "strips whitespace for each row" do
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
group = RSpec::Core::ExampleGroup.describe(" root ")
context1 = group.describe(" nested ")
context1.example(" example 1 ") {}
context1.example(" example 2 ", :pending => true){}
context1.example(" example 3 ") { fail }
group.run(RSpec::Core::Reporter.new(RSpec.configuration, formatter))
expect(output.string).to eql("
root
nested
example 1
example 2 (PENDING: No reason given)
example 3 (FAILED - 1)
")
end
end
end