/
file_finder_spec.rb
37 lines (30 loc) · 1.06 KB
/
file_finder_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
# frozen_string_literal: true
RSpec.describe RuboCop::FileFinder, :isolated_environment do
include FileHelper
subject(:finder) { Class.new.include(described_class).new }
before do
create_empty_file('file')
create_empty_file(File.join('dir', 'file'))
end
describe '#find_file_upwards' do
it 'returns a file to be found upwards' do
expect(finder.find_file_upwards('file', 'dir'))
.to eq(File.expand_path('file', 'dir'))
expect(finder.find_file_upwards('file', Dir.pwd))
.to eq(File.expand_path('file'))
end
it 'returns nil when file is not found' do
expect(finder.find_file_upwards('file2', 'dir')).to be(nil)
end
end
describe '#find_files_upwards' do
it 'returns an array of files to be found upwards' do
expect(finder.find_files_upwards('file', 'dir'))
.to eq([File.expand_path('file', 'dir'),
File.expand_path('file')])
end
it 'returns an empty array when file is not found' do
expect(finder.find_files_upwards('xyz', 'dir')).to eq([])
end
end
end