-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
junit_formatter_spec.rb
55 lines (48 loc) · 1.58 KB
/
junit_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
# frozen_string_literal: true
RSpec.describe RuboCop::Formatter::JUnitFormatter do
subject(:formatter) { described_class.new(output) }
let(:output) { StringIO.new }
describe '#file_finished' do
it 'displays parsable text' do
cop = RuboCop::Cop::Cop.new
source_buffer = Parser::Source::Buffer.new('test', 1)
source_buffer.source = %w[foo bar baz].join("\n")
cop.add_offense(
nil,
location: Parser::Source::Range.new(source_buffer, 0, 1),
message: 'message 1'
)
cop.add_offense(
nil,
location: Parser::Source::Range.new(source_buffer, 9, 10),
message: 'message 2'
)
formatter.file_finished('test_1', cop.offenses)
formatter.file_finished('test_2', cop.offenses)
formatter.finished(nil)
expect(output.string).to eq(<<~XML.chop)
<?xml version='1.0'?>
<testsuites>
<testsuite name='rubocop'>
<testcase classname='test_1' name='Cop/Cop'>
<failure type='Cop/Cop' message='message 1'>
test:1:1
</failure>
<failure type='Cop/Cop' message='message 2'>
test:3:2
</failure>
</testcase>
<testcase classname='test_2' name='Cop/Cop'>
<failure type='Cop/Cop' message='message 1'>
test:1:1
</failure>
<failure type='Cop/Cop' message='message 2'>
test:3:2
</failure>
</testcase>
</testsuite>
</testsuites>
XML
end
end
end