Sha256: 155bb62704b5682258b0e97bc874af41580390809e44a460b8cc8d14a27da73c

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'fedux_org_stdlib/recursive_file_finder'

RSpec.describe RecursiveFileFinder do
  context '#file' do
    it 'returns path to found file' do
      touch_file 'test.txt'
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('.'))
      expect(finder.file).to eq Pathname.new(absolute_path('test.txt'))
    end

    it 'runs up file hierarchy' do
      touch_file 'test.txt'
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
      expect(finder.file).to eq Pathname.new(absolute_path('test.txt'))
    end

    it 'runs up file hierarchy and finds it in between' do
      touch_file 'dir1/test.txt'
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
      expect(finder.file).to eq Pathname.new(absolute_path('dir1/test.txt'))
    end

    it 'fails if file was not found' do
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
      expect { finder.file }.to raise_error Errno::ENOENT
    end

    it 'returns nil if told to to so' do
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'), raise_error: false)
      expect(finder.file).to be nil
    end
  end

  context '#directory' do
    it 'returns the directory where the file was found' do
      touch_file 'test.txt'
      finder = RecursiveFileFinder.new(file_name: 'test.txt', working_directory: absolute_path('dir1/dir2/'))
      expect(finder.directory).to eq Pathname.new(absolute_path('.'))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.9.0 spec/recursive_file_finder_spec.rb