-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
multiline_array_brace_layout_spec.rb
61 lines (51 loc) · 1.5 KB
/
multiline_array_brace_layout_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Layout::MultilineArrayBraceLayout, :config do
subject(:cop) { described_class.new(config) }
let(:cop_config) { { 'EnforcedStyle' => 'symmetrical' } }
it 'ignores implicit arrays' do
expect_no_offenses(<<~RUBY)
foo = a,
b
RUBY
end
it 'ignores single-line arrays' do
expect_no_offenses('[a, b, c]')
end
it 'ignores empty arrays' do
expect_no_offenses('[]')
end
it_behaves_like 'multiline literal brace layout' do
let(:open) { '[' }
let(:close) { ']' }
end
it_behaves_like 'multiline literal brace layout method argument' do
let(:open) { '[' }
let(:close) { ']' }
let(:a) { 'a: 1' }
let(:b) { 'b: 2' }
end
it_behaves_like 'multiline literal brace layout trailing comma' do
let(:open) { '[' }
let(:close) { ']' }
end
context 'when comment present before closing brace' do
it 'corrects closing brace without crashing' do
expect_offense(<<~RUBY)
{
first_key: ['value a', # comment 1
'value b' # comment 2
],
^ The closing array brace must be on the same line as the last array element when the opening brace is on the same line as the first array element.
second_key: 'value c'
}
RUBY
expect_correction(<<~RUBY)
{
first_key: ['value a', # comment 1
'value b'], # comment 2
second_key: 'value c'
}
RUBY
end
end
end