/
space_before_semicolon_spec.rb
84 lines (68 loc) · 2.12 KB
/
space_before_semicolon_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Layout::SpaceBeforeSemicolon, :config do
let(:config) { RuboCop::Config.new('Layout/SpaceInsideBlockBraces' => brace_config) }
let(:brace_config) { {} }
it 'registers an offense and corrects space before semicolon' do
expect_offense(<<~RUBY)
x = 1 ; y = 2
^ Space found before semicolon.
RUBY
expect_correction(<<~RUBY)
x = 1; y = 2
RUBY
end
it 'does not register an offense for no space before semicolons' do
expect_no_offenses('x = 1; y = 2')
end
it 'registers an offense and corrects more than one space before a semicolon' do
expect_offense(<<~RUBY)
x = 1 ; y = 2
^^ Space found before semicolon.
RUBY
expect_correction(<<~RUBY)
x = 1; y = 2
RUBY
end
context 'inside block braces' do
shared_examples 'common behavior' do
it 'accepts no space between an opening brace and a semicolon' do
expect_no_offenses('test {; }')
end
end
context 'when EnforcedStyle for SpaceInsideBlockBraces is space' do
let(:brace_config) { { 'Enabled' => true, 'EnforcedStyle' => 'space' } }
it_behaves_like 'common behavior'
it 'accepts a space between an opening brace and a semicolon' do
expect_no_offenses('test { ; }')
end
end
context 'when EnforcedStyle for SpaceInsideBlockBraces is no_space' do
let(:brace_config) { { 'Enabled' => true, 'EnforcedStyle' => 'no_space' } }
it_behaves_like 'common behavior'
it 'registers an offense and corrects a space between an opening brace and a semicolon' do
expect_offense(<<~RUBY)
test { ; }
^ Space found before semicolon.
RUBY
expect_correction(<<~RUBY)
test {; }
RUBY
end
end
end
context 'heredocs' do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
<<~STR ; x = 1
^ Space found before semicolon.
text
STR
RUBY
expect_correction(<<~RUBY)
<<~STR; x = 1
text
STR
RUBY
end
end
end