-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
space_inside_parens_spec.rb
104 lines (89 loc) · 2.52 KB
/
space_inside_parens_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
100
101
102
103
104
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Layout::SpaceInsideParens, :config do
context 'when EnforcedStyle is no_space' do
let(:cop_config) { { 'EnforcedStyle' => 'no_space' } }
it 'registers an offense for spaces inside parens' do
expect_offense(<<~RUBY)
f( 3)
^ Space inside parentheses detected.
g = (a + 3 )
^ Space inside parentheses detected.
RUBY
expect_correction(<<~RUBY)
f(3)
g = (a + 3)
RUBY
end
it 'accepts parentheses in block parameter list' do
expect_no_offenses(<<~RUBY)
list.inject(Tms.new) { |sum, (label, item)|
}
RUBY
end
it 'accepts parentheses with no spaces' do
expect_no_offenses('split("\\n")')
end
it 'accepts parentheses with line break' do
expect_no_offenses(<<~RUBY)
f(
1)
RUBY
end
it 'accepts parentheses with comment and line break' do
expect_no_offenses(<<~RUBY)
f( # Comment
1)
RUBY
end
end
context 'when EnforcedStyle is space' do
let(:cop_config) { { 'EnforcedStyle' => 'space' } }
it 'registers an offense for no spaces inside parens' do
expect_offense(<<~RUBY)
f( 3)
^ No space inside parentheses detected.
g = (a + 3 )
^ No space inside parentheses detected.
split("\\n")
^ No space inside parentheses detected.
^ No space inside parentheses detected.
RUBY
expect_correction(<<~RUBY)
f( 3 )
g = ( a + 3 )
split( "\\n" )
RUBY
end
it 'registers an offense in block parameter list with no spaces' do
expect_offense(<<~RUBY)
list.inject( Tms.new ) { |sum, (label, item)|
^ No space inside parentheses detected.
^ No space inside parentheses detected.
}
RUBY
expect_correction(<<~RUBY)
list.inject( Tms.new ) { |sum, ( label, item )|
}
RUBY
end
it 'accepts parentheses with spaces' do
expect_no_offenses(<<~RUBY)
f( 3 )
g = ( a + 3 )
split( "\\n" )
RUBY
end
it 'accepts parentheses with line break' do
expect_no_offenses(<<~RUBY)
f(
1 )
RUBY
end
it 'accepts parentheses with comment and line break' do
expect_no_offenses(<<~RUBY)
f( # Comment
1 )
RUBY
end
end
end