forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
empty_file_spec.rb
40 lines (34 loc) · 1.04 KB
/
empty_file_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::EmptyFile, :config do
let(:commissioner) { RuboCop::Cop::Commissioner.new([cop]) }
let(:offenses) { commissioner.investigate(processed_source).offenses }
let(:cop_config) do
{ 'AllowComments' => true }
end
let(:source) { '' }
it 'registers an offense when the file is empty' do
expect(offenses.size).to eq(1)
offense = offenses.first
expect(offense.message).to eq('Empty file detected.')
expect(offense.severity).to eq(:warning)
end
it 'does not register an offense when the file contains code' do
expect_no_offenses(<<~RUBY)
foo.bar
RUBY
end
it 'does not register an offense when the file contains comments' do
expect_no_offenses(<<~RUBY)
# comment
RUBY
end
context 'when AllowComments is false' do
let(:cop_config) do
{ 'AllowComments' => false }
end
let(:source) { '# comment' }
it 'registers an offense when the file contains comments' do
expect(offenses.size).to eq(1)
end
end
end