Skip to content

Commit

Permalink
Add spec for CommentConfig#comment_only_line?
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Eres authored and bbatsov committed Mar 12, 2021
1 parent 027655d commit bd7f60b
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion spec/rubocop/comment_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def some_method
puts 'Disabling indented single line' # rubocop:disable Layout/LineLength
end
# 18
string = <<END
string = <<~END
This is a string not a real comment # rubocop:disable Style/Loop
END
Expand Down Expand Up @@ -226,4 +226,51 @@ def some_method
expect(extra.values.first).to eq ['Metrics/MethodLength', 'Security/Eval']
end
end

describe 'comment_only_line?' do
let(:source) do
<<~RUBY
# rubocop:disable Metrics/MethodLength 01
def some_method
puts 'foo'
end
# rubocop:enable Metrics/MethodLength 05
code = 'This is evil.'
eval(code) # rubocop:disable Security/Eval
RUBY
end

context 'when line contains only comment' do
[1, 5].each do |line_number|
it 'returns true' do
expect(comment_config.comment_only_line?(line_number)).to be true
end
end
end

context 'when line is empty' do
[6].each do |line_number|
it 'returns true' do
expect(comment_config.comment_only_line?(line_number)).to be true
end
end
end

context 'when line contains only code' do
[2, 3, 4, 7].each do |line_number|
it 'returns false' do
expect(comment_config.comment_only_line?(line_number)).to be false
end
end
end

context 'when line contains code and comment' do
[8].each do |line_number|
it 'returns false' do
expect(comment_config.comment_only_line?(line_number)).to be false
end
end
end
end
end

0 comments on commit bd7f60b

Please sign in to comment.