Last active
November 21, 2018 10:04
-
-
Save marzdgzmn/e7a1c04a62a7a79caba0410d06cf6dbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context 'when a custom script is provided' do | |
mirror_with_custom_script = OpenStruct.new(name: 'dummy_mirror', | |
local_dir: tmp_dir, | |
custom_script: true) | |
let(:sync) { Sync.new(mirror_with_custom_script) } | |
it 'should run the custom script instead of the rsync gem' do | |
expect(Marz::Rsync).not_to receive(:run) | |
expect(sync).to receive(:execute_custom_script).with(mirror_with_custom_script.custom_script) | |
sync.run | |
end | |
context 'when the custom script succeeds' do | |
it 'should update database sync status to SUCCESS' do | |
puts mirror_with_custom_script.custom_script | |
expect(DB).to receive(:update_sync_result).with(SyncStatus::SUCCESS) | |
sync.run | |
end | |
end | |
context 'when it raises Errno::ENOENT' do | |
mirror_with_custom_script.custom_script = 'nonExistingScript' | |
it 'should update database sync status to FAILED' do | |
allow(sync).to receive(:exit).and_throw :exit | |
expect(DB).to receive(:update_sync_result).with(SyncStatus::FAILED) | |
expect { sync.run }.to throw_symbol :exit | |
end | |
it 'should log the error' do | |
allow(sync).to receive(:exit).and_throw :exit | |
expect(logger).to receive(:log_error).with(/No such file or directory - nonExistingScript/) | |
expect { sync.run }.to throw_symbol :exit | |
end | |
end | |
context 'when the custom script fails' do | |
it 'should update database sync status to FAILED without logging anything' do | |
mirror_with_custom_script.custom_script = '(exit 1)' | |
allow(sync).to receive(:exit).and_throw :exit | |
expect(DB).to receive(:update_sync_result).with(SyncStatus::FAILED) | |
expect(logger).not_to receive(:log_error) | |
expect { sync.run }.to throw_symbol :exit | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment