Implement Remote::FS#dir?
This commit is contained in:
parent
dba8a7aeee
commit
9d7af04d28
@ -14,6 +14,12 @@ module Producer
|
|||||||
@sftp ||= @remote.session.sftp.connect
|
@sftp ||= @remote.session.sftp.connect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dir?(path)
|
||||||
|
sftp.stat!(path).directory?
|
||||||
|
rescue Net::SFTP::StatusException
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def file?(path)
|
def file?(path)
|
||||||
sftp.stat!(path).file?
|
sftp.stat!(path).file?
|
||||||
rescue Net::SFTP::StatusException
|
rescue Net::SFTP::StatusException
|
||||||
|
@ -31,6 +31,45 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#dir?' do
|
||||||
|
let(:sftp) { double('sftp').as_null_object }
|
||||||
|
let(:path) { 'some_directory_path' }
|
||||||
|
let(:stat) { double 'stat' }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(fs).to receive(:sftp) { sftp }
|
||||||
|
allow(sftp).to receive(:stat!).with(path) { stat }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when path given as argument is a directory' do
|
||||||
|
before { allow(stat).to receive(:directory?) { true } }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(fs.dir? path).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when path given as argument is not a directory' do
|
||||||
|
before { allow(stat).to receive(:directory?) { false } }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(fs.dir? path).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when querying the path raises a Net::SFTP::StatusException' do
|
||||||
|
before do
|
||||||
|
response = double 'response', code: '42', message: 'some message'
|
||||||
|
ex = Net::SFTP::StatusException.new(response)
|
||||||
|
allow(sftp).to receive(:stat!).with(path).and_raise(ex)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(fs.dir? path).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
|
# FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
|
||||||
# part of net-ssh story helpers, which are more close to integration tests.
|
# part of net-ssh story helpers, which are more close to integration tests.
|
||||||
describe '#file?', :ssh do
|
describe '#file?', :ssh do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user