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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# frozen_string_literal: true
require_relative '../../../../tooling/lib/tooling/test_map_generator'
require_relative '../../../support/helpers/file_read_helpers'
RSpec.describe Tooling::TestMapGenerator do
include FileReadHelpers
subject { described_class.new }
describe '#parse' do
let(:yaml1) do
<<~YAML
---
:type: Crystalball::ExecutionMap
:commit: a7d57d333042f3b0334b2f8a282354eef7365976
:timestamp: 1602668405
:version:
---
"./spec/factories_spec.rb[1]":
- lib/gitlab/current_settings.rb
- lib/feature.rb
- lib/gitlab/marginalia.rb
YAML
end
let(:yaml2) do
<<~YAML
---
:type: Crystalball::ExecutionMap
:commit: 74056e8d9cf3773f43faa1cf5416f8779c8284c8
:timestamp: 1602671965
:version:
---
"./spec/models/project_spec.rb[1]":
- lib/gitlab/current_settings.rb
- lib/feature.rb
- lib/gitlab/marginalia.rb
YAML
end
let(:yaml3) do
<<~YAML
---
:type: Crystalball::ExecutionMap
:commit: 74056e8d9cf3773f43faa1cf5416f8779c8284c9
:timestamp: 1602671965
:version:
---
YAML
end
let(:pathname) { instance_double(Pathname) }
before do
stub_file_read('yaml1.yml', content: yaml1)
stub_file_read('yaml2.yml', content: yaml2)
stub_file_read('yaml3.yml', content: yaml3)
end
context 'with single yaml' do
let(:expected_mapping) do
{
'lib/gitlab/current_settings.rb' => [
'spec/factories_spec.rb'
],
'lib/feature.rb' => [
'spec/factories_spec.rb'
],
'lib/gitlab/marginalia.rb' => [
'spec/factories_spec.rb'
]
}
end
it 'parses crystalball data into test mapping' do
subject.parse('yaml1.yml')
expect(subject.mapping.keys).to match_array(expected_mapping.keys)
end
it 'stores test files without example uid' do
subject.parse('yaml1.yml')
expected_mapping.each do |file, tests|
expect(subject.mapping[file]).to match_array(tests)
end
end
it 'displays a warning when report has no examples' do
expect { subject.parse('yaml3.yml') }.to output(%|No examples in yaml3.yml! Metadata: {:type=>"Crystalball::ExecutionMap", :commit=>"74056e8d9cf3773f43faa1cf5416f8779c8284c9", :timestamp=>1602671965, :version=>nil}\n|).to_stdout
end
end
context 'with multiple yamls' do
let(:expected_mapping) do
{
'lib/gitlab/current_settings.rb' => [
'spec/factories_spec.rb',
'spec/models/project_spec.rb'
],
'lib/feature.rb' => [
'spec/factories_spec.rb',
'spec/models/project_spec.rb'
],
'lib/gitlab/marginalia.rb' => [
'spec/factories_spec.rb',
'spec/models/project_spec.rb'
]
}
end
it 'parses crystalball data into test mapping' do
subject.parse(%w[yaml1.yml yaml2.yml])
expect(subject.mapping.keys).to match_array(expected_mapping.keys)
end
it 'stores test files without example uid' do
subject.parse(%w[yaml1.yml yaml2.yml])
expected_mapping.each do |file, tests|
expect(subject.mapping[file]).to match_array(tests)
end
end
end
end
end
|