forked from backup/backup
/
dependency_spec.rb
49 lines (42 loc) · 1.38 KB
/
dependency_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
38
39
40
41
42
43
44
45
46
47
48
49
# encoding: utf-8
require File.expand_path('../spec_helper.rb', __FILE__)
describe Backup::Dependency do
before do
Backup::Dependency.stubs(:all).returns(
'net-sftp' => {
:require => 'net/sftp',
:version => '~> 2.0.5',
:for => 'SFTP Protocol (SFTP Storage)'
})
end
describe ".load" do
it "should load and require given dependency" do
Backup::Dependency.expects(:gem).with("net-sftp", "~> 2.0.5")
Backup::Dependency.expects(:require).with("net/sftp")
Backup::Dependency.load("net-sftp")
end
context "on a missing dependency" do
before do
Backup::Dependency.stubs(:gem).raises(LoadError)
end
it "should display error message" do
Backup::Logger.expects(:error).with do |exception|
exception.message.should == "Dependency::LoadError: Dependency missing
Dependency required for:
SFTP Protocol (SFTP Storage)
To install the gem, issue the following command:
> gem install net-sftp -v '~> 2.0.5'
Please try again after installing the missing dependency."
end
expect do
Backup::Dependency.load("net-sftp")
end.to raise_error(SystemExit)
end
it "should exit with status code 1" do
expect do
Backup::Dependency.load("net-sftp")
end.to raise_error { |exit| exit.status.should be(1) }
end
end
end
end