forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_comments_spec.rb
71 lines (60 loc) · 1.41 KB
/
block_comments_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::BlockComments do
subject(:cop) { described_class.new }
it 'registers an offense for block comments' do
expect_offense(<<-RUBY.strip_indent)
=begin
^^^^^^ Do not use block comments.
comment
=end
RUBY
end
it 'accepts regular comments' do
expect_no_offenses('# comment')
end
it 'auto-corrects a block comment into a regular comment' do
new_source = autocorrect_source(<<-RUBY.strip_indent)
=begin
comment line 1
comment line 2
=end
def foo
end
RUBY
expect(new_source).to eq(<<-RUBY.strip_indent)
# comment line 1
#
# comment line 2
def foo
end
RUBY
end
it 'auto-corrects an empty block comment by removing it' do
new_source = autocorrect_source(<<-RUBY.strip_indent)
=begin
=end
def foo
end
RUBY
expect(new_source).to eq(<<-RUBY.strip_indent)
def foo
end
RUBY
end
it 'auto-corrects a block comment into a regular comment (without trailing' \
'newline)' do
source = <<-RUBY.strip_indent
=begin
comment line 1
comment line 2
=end
RUBY
new_source = autocorrect_source(source.chomp)
expected_source = <<-RUBY.strip_indent
# comment line 1
#
# comment line 2
RUBY
expect(new_source).to eq(expected_source)
end
end