Refactor Remote::FS specs
This commit is contained in:
parent
f45d0b5a20
commit
64a6ed678a
@ -3,8 +3,9 @@ require 'spec_helper'
|
|||||||
module Producer::Core
|
module Producer::Core
|
||||||
class Remote
|
class Remote
|
||||||
describe FS do
|
describe FS do
|
||||||
let(:sftp) { double 'sftp' }
|
let(:sftp_file) { double 'sftp_file' }
|
||||||
subject(:fs) { FS.new(sftp) }
|
let(:sftp) { double('sftp', file: sftp_file) }
|
||||||
|
subject(:fs) { FS.new(sftp) }
|
||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
it 'assigns the sftp session' do
|
it 'assigns the sftp session' do
|
||||||
@ -99,14 +100,12 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#file_read' do
|
describe '#file_read' do
|
||||||
let(:file) { double 'file' }
|
|
||||||
let(:f) { double 'f' }
|
let(:f) { double 'f' }
|
||||||
let(:path) { 'some_file_path' }
|
let(:path) { 'some_file_path' }
|
||||||
let(:content) { 'some_content' }
|
let(:content) { 'some_content' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(sftp).to receive(:file) { file }
|
allow(sftp_file).to receive(:open).and_yield(f)
|
||||||
allow(file).to receive(:open).and_yield(f)
|
|
||||||
allow(f).to receive(:read) { content }
|
allow(f).to receive(:read) { content }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -118,7 +117,7 @@ module Producer::Core
|
|||||||
before do
|
before do
|
||||||
response = double 'response', code: '42', message: 'some message'
|
response = double 'response', code: '42', message: 'some message'
|
||||||
ex = Net::SFTP::StatusException.new(response)
|
ex = Net::SFTP::StatusException.new(response)
|
||||||
allow(file).to receive(:open).and_raise(ex)
|
allow(sftp_file).to receive(:open).and_raise(ex)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nil' do
|
it 'returns nil' do
|
||||||
@ -128,23 +127,18 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#file_write' do
|
describe '#file_write' do
|
||||||
let(:file) { double 'file' }
|
|
||||||
let(:path) { 'some_file_path' }
|
let(:path) { 'some_file_path' }
|
||||||
let(:content) { 'some_content' }
|
let(:content) { 'some_content' }
|
||||||
|
|
||||||
before do
|
|
||||||
allow(sftp).to receive(:file) { file }
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'opens the file' do
|
it 'opens the file' do
|
||||||
expect(file).to receive(:open).with(path, 'w')
|
expect(sftp_file).to receive(:open).with(path, 'w')
|
||||||
fs.file_write path, content
|
fs.file_write path, content
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'writes the content' do
|
it 'writes the content' do
|
||||||
expect(file).to receive(:open).with(any_args) do |&b|
|
expect(sftp_file).to receive(:open).with(any_args) do |&b|
|
||||||
expect(file).to receive(:write).with(content)
|
expect(sftp_file).to receive(:write).with(content)
|
||||||
b.call file
|
b.call sftp_file
|
||||||
end
|
end
|
||||||
fs.file_write path, content
|
fs.file_write path, content
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user