forked from rubocop/rubocop
/
require_relative_self_path_spec.rb
39 lines (33 loc) · 1.16 KB
/
require_relative_self_path_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::RequireRelativeSelfPath, :config do
it 'registers an offense when using `require_relative` with self file path argument' do
expect_offense(<<~RUBY, 'foo.rb')
require_relative 'foo'
^^^^^^^^^^^^^^^^^^^^^^ Remove the `require_relative` that requires itself.
require_relative 'bar'
RUBY
expect_correction(<<~RUBY)
require_relative 'bar'
RUBY
end
it 'registers an offense when using `require_relative` with self file path argument (with ext)' do
expect_offense(<<~RUBY, 'foo.rb')
require_relative 'foo.rb'
^^^^^^^^^^^^^^^^^^^^^^^^^ Remove the `require_relative` that requires itself.
require_relative 'bar'
RUBY
expect_correction(<<~RUBY)
require_relative 'bar'
RUBY
end
it 'does not register an offense when using `require_relative` without self file path argument' do
expect_no_offenses(<<~RUBY, 'foo.rb')
require_relative 'bar'
RUBY
end
it 'does not register an offense when using `require_relative` without argument' do
expect_no_offenses(<<~RUBY, 'foo.rb')
require_relative
RUBY
end
end