/
disabled_lines_formatter_spec.rb
83 lines (69 loc) · 2.25 KB
/
disabled_lines_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
# frozen_string_literal: true
RSpec.describe RuboCop::Formatter::DisabledLinesFormatter do
subject(:formatter) { described_class.new(output) }
let(:output) { StringIO.new }
let(:files) do
%w[lib/rubocop.rb spec/spec_helper.rb exe/rubocop].map do |path|
File.expand_path(path)
end
end
let(:file_started) do
formatter.file_started(files.first, cop_disabled_line_ranges)
end
describe '#file_started' do
before { formatter.started(files) }
context 'when no disable cop comments are detected' do
let(:cop_disabled_line_ranges) { {} }
it 'does not add to cop_disabled_line_ranges' do
expect { file_started }.not_to(
change(formatter, :cop_disabled_line_ranges)
)
end
end
context 'when any disable cop comments are detected' do
let(:cop_disabled_line_ranges) do
{ cop_disabled_line_ranges: { 'LineLength' => [1..1] } }
end
it 'merges the changes into cop_disabled_line_ranges' do
expect { file_started }.to(
change(formatter, :cop_disabled_line_ranges)
)
end
end
end
describe '#finished' do
context 'when there disabled cops detected' do
let(:cop_disabled_line_ranges) do
{
cop_disabled_line_ranges: {
'LineLength' => [1..1],
'ClassLength' => [1..Float::INFINITY]
}
}
end
let(:offenses) do
[
RuboCop::Cop::Offense.new(:convention, location, 'Class too long.',
'ClassLength', :disabled),
RuboCop::Cop::Offense.new(:convention, location, 'Line too long.',
'LineLength', :uncorrected)
]
end
let(:location) { OpenStruct.new(line: 3) }
before do
formatter.started(files)
formatter.file_started('lib/rubocop.rb', cop_disabled_line_ranges)
formatter.file_finished('lib/rubocop.rb', offenses)
end
it 'lists disabled cops by file' do
formatter.finished(files)
expect(output.string)
.to eq(<<~OUTPUT)
Cops disabled line ranges:
lib/rubocop.rb:1..1: LineLength
lib/rubocop.rb:1..Infinity: ClassLength
OUTPUT
end
end
end
end