-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
leading_empty_lines_spec.rb
117 lines (94 loc) · 2.64 KB
/
leading_empty_lines_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
105
106
107
108
109
110
111
112
113
114
115
116
117
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Layout::LeadingEmptyLines, :config do
it 'allows an empty input' do
expect_no_offenses('')
end
it 'allows blank lines without any comments or code' do
expect_no_offenses("\n")
end
it 'accepts not having a blank line before a class' do
expect_no_offenses(<<~RUBY)
class Foo
end
RUBY
end
it 'accepts not having a blank line before code' do
expect_no_offenses(<<~RUBY)
puts 1
RUBY
end
it 'accepts not having a blank line before a comment' do
expect_no_offenses(<<~RUBY)
# something
RUBY
end
it 'registers an offense and corrects a new line before a class' do
expect_offense(<<~RUBY)
class Foo
^^^^^ Unnecessary blank line at the beginning of the source.
end
RUBY
expect_correction(<<~RUBY)
class Foo
end
RUBY
end
it 'registers an offense and corrects a new line before code' do
expect_offense(<<~RUBY)
puts 1
^^^^ Unnecessary blank line at the beginning of the source.
RUBY
expect_correction(<<~RUBY)
puts 1
RUBY
end
it 'registers an offense and corrects a new line before a comment' do
expect_offense(<<~RUBY)
# something
^^^^^^^^^^^ Unnecessary blank line at the beginning of the source.
RUBY
expect_correction(<<~RUBY)
# something
RUBY
end
it 'registers an offense and corrects multiple new lines before a class' do
expect_offense(<<~RUBY)
class Foo
^^^^^ Unnecessary blank line at the beginning of the source.
end
RUBY
expect_correction(<<~RUBY)
class Foo
end
RUBY
end
context 'auto-correct' do
context 'in collaboration' do
let(:config) do
RuboCop::Config.new('Layout/SpaceAroundEqualsInParameterDefault' => {
'SupportedStyles' => [:space],
'EnforcedStyle' => :space
})
end
let(:cops) do
cop_classes = [
described_class,
::RuboCop::Cop::Layout::SpaceAroundEqualsInParameterDefault
]
::RuboCop::Cop::Registry.new(cop_classes)
end
it 'does not invoke conflicts with other cops' do
source_with_offenses = <<~RUBY
def bar(arg =1); end
RUBY
options = { auto_correct: true, stdin: true }
team = RuboCop::Cop::Team.new(cops, config, options)
team.inspect_file(parse_source(source_with_offenses, nil))
new_source = options[:stdin]
expect(new_source).to eq(<<~RUBY)
def bar(arg = 1); end
RUBY
end
end
end
end