-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
directive_comment_spec.rb
99 lines (74 loc) · 2.48 KB
/
directive_comment_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
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true
RSpec.describe RuboCop::DirectiveComment do
subject(:directive_comment) { described_class.new(comment) }
let(:comment) { instance_double(Parser::Source::Comment, text: text) }
let(:comment_cop_names) { 'all' }
let(:text) { "#rubocop:enable #{comment_cop_names}" }
describe '#cops' do
subject(:cops) { directive_comment.cops }
context 'all' do
let(:comment_cop_names) { 'all' }
it 'returns [all]' do
expect(cops).to eq(%w[all])
end
end
context 'single cop' do
let(:comment_cop_names) { 'Metrics/AbcSize' }
it 'returns [Metrics/AbcSize]' do
expect(cops).to eq(%w[Metrics/AbcSize])
end
end
context 'single cop duplicated' do
let(:comment_cop_names) { 'Metrics/AbcSize,Metrics/AbcSize' }
it 'returns [Metrics/AbcSize]' do
expect(cops).to eq(%w[Metrics/AbcSize])
end
end
context 'multiple cops' do
let(:comment_cop_names) { 'Style/Not, Metrics/AbcSize' }
it 'returns the cops in alphabetical order' do
expect(cops).to eq(%w[Metrics/AbcSize Style/Not])
end
end
end
describe '#match?' do
subject(:match) { directive_comment.match?(cop_names) }
let(:comment_cop_names) { 'Metrics/AbcSize, Metrics/PerceivedComplexity, Style/Not' }
context 'no comment_cop_names' do
let(:cop_names) { [] }
it 'returns false' do
expect(match).to eq(false)
end
end
context 'same cop names as in the comment' do
let(:cop_names) { %w[Metrics/AbcSize Metrics/PerceivedComplexity Style/Not] }
it 'returns true' do
expect(match).to eq(true)
end
end
context 'same cop names as in the comment in a different order' do
let(:cop_names) { %w[Style/Not Metrics/AbcSize Metrics/PerceivedComplexity] }
it 'returns true' do
expect(match).to eq(true)
end
end
context 'subset of names' do
let(:cop_names) { %w[Metrics/AbcSize Style/Not] }
it 'returns false' do
expect(match).to eq(false)
end
end
context 'superset of names' do
let(:cop_names) { %w[Lint/Void Metrics/AbcSize Metrics/PerceivedComplexity Style/Not] }
it 'returns false' do
expect(match).to eq(false)
end
end
context 'duplicate names' do
let(:cop_names) { %w[Metrics/AbcSize Metrics/AbcSize Metrics/PerceivedComplexity Style/Not] }
it 'returns true' do
expect(match).to eq(true)
end
end
end
end