/
multiline_method_call_brace_layout_spec.rb
80 lines (66 loc) · 1.83 KB
/
multiline_method_call_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Layout::MultilineMethodCallBraceLayout, :config do
let(:cop_config) { { 'EnforcedStyle' => 'symmetrical' } }
it 'ignores implicit calls' do
expect_no_offenses(<<~RUBY)
foo 1,
2
RUBY
end
it 'ignores single-line calls' do
expect_no_offenses('foo(1,2)')
end
it 'ignores calls without arguments' do
expect_no_offenses('puts')
end
it 'ignores calls with an empty brace' do
expect_no_offenses('puts()')
end
it 'ignores calls with a multiline empty brace ' do
expect_no_offenses(<<~RUBY)
puts(
)
RUBY
end
it_behaves_like 'multiline literal brace layout' do
let(:open) { 'foo(' }
let(:close) { ')' }
end
it_behaves_like 'multiline literal brace layout trailing comma' do
let(:open) { 'foo(' }
let(:close) { ')' }
end
context 'when EnforcedStyle is new_line' do
let(:cop_config) { { 'EnforcedStyle' => 'new_line' } }
it 'still ignores single-line calls' do
expect_no_offenses('puts("Hello world!")')
end
it 'ignores single-line calls with multi-line receiver' do
expect_no_offenses(<<~RUBY)
[
].join(" ")
RUBY
end
it 'ignores single-line calls with multi-line receiver with leading dot' do
expect_no_offenses(<<~RUBY)
[
]
.join(" ")
RUBY
end
end
context 'when comment present before closing brace' do
it 'corrects closing brace without crashing' do
expect_offense(<<~RUBY)
super(bar(baz,
ham # comment
))
^ Closing method call brace must be on the same line as the last argument when opening brace is on the same line as the first argument.
RUBY
expect_correction(<<~RUBY)
super(bar(baz,
ham)) # comment
RUBY
end
end
end