backup 3.0.27 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
@@ -1,148 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Encryptor::OpenSSL do
|
6
|
-
let(:encryptor) do
|
7
|
-
Backup::Encryptor::OpenSSL.new do |e|
|
8
|
-
e.password = 'mypassword'
|
9
|
-
e.password_file = '/my/password/file'
|
10
|
-
e.base64 = true
|
11
|
-
e.salt = true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a subclass of Encryptor::Base' do
|
16
|
-
Backup::Encryptor::OpenSSL.
|
17
|
-
superclass.should == Backup::Encryptor::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
after { Backup::Encryptor::OpenSSL.clear_defaults! }
|
22
|
-
|
23
|
-
it 'should load pre-configured defaults' do
|
24
|
-
Backup::Encryptor::OpenSSL.any_instance.expects(:load_defaults!)
|
25
|
-
encryptor
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when no pre-configured defaults have been set' do
|
29
|
-
it 'should use the values given' do
|
30
|
-
encryptor.password.should == 'mypassword'
|
31
|
-
encryptor.password_file.should == '/my/password/file'
|
32
|
-
encryptor.base64.should == true
|
33
|
-
encryptor.salt.should == true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should use default values if none are given' do
|
37
|
-
encryptor = Backup::Encryptor::OpenSSL.new
|
38
|
-
encryptor.password.should be_nil
|
39
|
-
encryptor.password_file.should be_nil
|
40
|
-
encryptor.base64.should be_false
|
41
|
-
encryptor.salt.should be_true
|
42
|
-
end
|
43
|
-
end # context 'when no pre-configured defaults have been set'
|
44
|
-
|
45
|
-
context 'when pre-configured defaults have been set' do
|
46
|
-
before do
|
47
|
-
Backup::Encryptor::OpenSSL.defaults do |e|
|
48
|
-
e.password = 'default_password'
|
49
|
-
e.password_file = '/default/password/file'
|
50
|
-
e.base64 = 'default_base64'
|
51
|
-
e.salt = 'default_salt'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should use pre-configured defaults' do
|
56
|
-
encryptor = Backup::Encryptor::OpenSSL.new
|
57
|
-
encryptor.password = 'default_password'
|
58
|
-
encryptor.password_file = '/default/password/file'
|
59
|
-
encryptor.base64 = 'default_base64'
|
60
|
-
encryptor.salt = 'default_salt'
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should override pre-configured defaults' do
|
64
|
-
encryptor.password.should == 'mypassword'
|
65
|
-
encryptor.password_file.should == '/my/password/file'
|
66
|
-
encryptor.base64.should == true
|
67
|
-
encryptor.salt.should == true
|
68
|
-
end
|
69
|
-
end # context 'when pre-configured defaults have been set'
|
70
|
-
end # describe '#initialize'
|
71
|
-
|
72
|
-
describe '#encrypt_with' do
|
73
|
-
it 'should yield the encryption command and extension' do
|
74
|
-
encryptor.expects(:log!)
|
75
|
-
encryptor.expects(:utility).with(:openssl).returns('openssl_cmd')
|
76
|
-
encryptor.expects(:options).returns('cmd_options')
|
77
|
-
|
78
|
-
encryptor.encrypt_with do |command, ext|
|
79
|
-
command.should == 'openssl_cmd cmd_options'
|
80
|
-
ext.should == '.enc'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#options' do
|
86
|
-
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
87
|
-
|
88
|
-
before do
|
89
|
-
# salt is true by default
|
90
|
-
encryptor.salt = false
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'with no options given' do
|
94
|
-
it 'should always include cipher command' do
|
95
|
-
encryptor.send(:options).should match(/^aes-256-cbc\s.*$/)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should add #password option whenever #password_file not given' do
|
99
|
-
encryptor.send(:options).should ==
|
100
|
-
"aes-256-cbc -k ''"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when #password_file is given' do
|
105
|
-
before { encryptor.password_file = 'password_file' }
|
106
|
-
|
107
|
-
it 'should add #password_file option' do
|
108
|
-
encryptor.send(:options).should ==
|
109
|
-
'aes-256-cbc -pass file:password_file'
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should add #password_file option even when #password given' do
|
113
|
-
encryptor.password = 'password'
|
114
|
-
encryptor.send(:options).should ==
|
115
|
-
'aes-256-cbc -pass file:password_file'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when #password is given (without #password_file given)' do
|
120
|
-
before { encryptor.password = 'password' }
|
121
|
-
|
122
|
-
it 'should include the given password in the #password option' do
|
123
|
-
encryptor.send(:options).should ==
|
124
|
-
"aes-256-cbc -k 'password'"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when #base64 is true' do
|
129
|
-
before { encryptor.base64 = true }
|
130
|
-
|
131
|
-
it 'should add the option' do
|
132
|
-
encryptor.send(:options).should ==
|
133
|
-
"aes-256-cbc -base64 -k ''"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'when #salt is true' do
|
138
|
-
before { encryptor.salt = true }
|
139
|
-
|
140
|
-
it 'should add the option' do
|
141
|
-
encryptor.send(:options).should ==
|
142
|
-
"aes-256-cbc -salt -k ''"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end # describe '#options'
|
147
|
-
|
148
|
-
end
|
data/spec/errors_spec.rb
DELETED
@@ -1,306 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
# Note: none of these tests require the use of the ErrorsHelper
|
6
|
-
describe 'Errors::Error' do
|
7
|
-
let(:klass) { Backup::Errors::Error }
|
8
|
-
|
9
|
-
it 'allow errors to cascade through the system' do
|
10
|
-
class ErrorA < klass; end
|
11
|
-
class ErrorB < klass; end
|
12
|
-
class ErrorC < klass; end
|
13
|
-
class ErrorD < klass; end
|
14
|
-
|
15
|
-
expect do
|
16
|
-
begin
|
17
|
-
begin
|
18
|
-
begin
|
19
|
-
raise ErrorA, 'an error occurred in Zone A'
|
20
|
-
rescue => err
|
21
|
-
raise ErrorB.wrap(err, <<-EOS)
|
22
|
-
an error occurred in Zone B
|
23
|
-
|
24
|
-
the following error should give a reason
|
25
|
-
EOS
|
26
|
-
end
|
27
|
-
rescue => err
|
28
|
-
raise ErrorC.wrap(err)
|
29
|
-
end
|
30
|
-
rescue => err
|
31
|
-
raise ErrorD.wrap(err, 'an error occurred in Zone D')
|
32
|
-
end
|
33
|
-
end.to raise_error(ErrorD,
|
34
|
-
"ErrorD: an error occurred in Zone D\n" +
|
35
|
-
" Reason: ErrorC\n" +
|
36
|
-
" ErrorB: an error occurred in Zone B\n" +
|
37
|
-
" \n" +
|
38
|
-
" the following error should give a reason\n" +
|
39
|
-
" Reason: ErrorA\n" +
|
40
|
-
" an error occurred in Zone A"
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#initialize' do
|
45
|
-
|
46
|
-
it 'creates a StandardError' do
|
47
|
-
klass.new.should be_a_kind_of StandardError
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when given a message' do
|
51
|
-
|
52
|
-
it 'formats a simple message' do
|
53
|
-
err = klass.new('error message')
|
54
|
-
err.message.should == 'Error: error message'
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'formats a multi-line message' do
|
58
|
-
err = klass.new(" error message\n" +
|
59
|
-
" This is a multi-line error message.\n" +
|
60
|
-
"It should be properly indented. ")
|
61
|
-
|
62
|
-
err.message.should == "Error: error message\n" +
|
63
|
-
" This is a multi-line error message.\n" +
|
64
|
-
" It should be properly indented."
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when given an original error' do
|
68
|
-
|
69
|
-
it 'includes the original error' do
|
70
|
-
orig_err = StandardError.new('original message')
|
71
|
-
err = klass.new('error message', orig_err)
|
72
|
-
err.message.should == "Error: error message\n" +
|
73
|
-
" Reason: StandardError\n" +
|
74
|
-
" original message"
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'formats all messages' do
|
78
|
-
orig_err = StandardError.new(" original message\n" +
|
79
|
-
" This is a multi-line error message.\n" +
|
80
|
-
"It should be properly indented.")
|
81
|
-
err = klass.new(" error message\n" +
|
82
|
-
" This is a multi-line error message.\n" +
|
83
|
-
"It should be properly indented. ", orig_err)
|
84
|
-
|
85
|
-
err.message.should == "Error: error message\n" +
|
86
|
-
" This is a multi-line error message.\n" +
|
87
|
-
" It should be properly indented.\n" +
|
88
|
-
" Reason: StandardError\n" +
|
89
|
-
" original message\n" +
|
90
|
-
" This is a multi-line error message.\n" +
|
91
|
-
" It should be properly indented."
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'uses the original error backtrace' do
|
95
|
-
begin
|
96
|
-
raise StandardError.new
|
97
|
-
rescue => err
|
98
|
-
klass.new(nil, err).backtrace.
|
99
|
-
should == err.backtrace
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'reports if original error had no message' do
|
104
|
-
orig_err = StandardError.new
|
105
|
-
err = klass.new('error message', orig_err)
|
106
|
-
err.message.should == "Error: error message\n" +
|
107
|
-
" Reason: StandardError (no message given)"
|
108
|
-
end
|
109
|
-
|
110
|
-
end # context 'when given an original error'
|
111
|
-
|
112
|
-
context 'when given an original Errors::Error' do
|
113
|
-
let(:subklass) do
|
114
|
-
class SubKlass < klass; end
|
115
|
-
SubKlass
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'includes the original error' do
|
119
|
-
orig_err = subklass.new('original message')
|
120
|
-
err = klass.new('error message', orig_err)
|
121
|
-
err.message.should == "Error: error message\n" +
|
122
|
-
" Reason: SubKlass\n" +
|
123
|
-
" original message"
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'formats all messages' do
|
127
|
-
orig_err = subklass.new(" original message\n" +
|
128
|
-
" This is a multi-line error message.\n" +
|
129
|
-
"It should be properly indented.")
|
130
|
-
err = klass.new(" error message\n" +
|
131
|
-
" This is a multi-line error message.\n" +
|
132
|
-
"It should be properly indented. ", orig_err)
|
133
|
-
|
134
|
-
err.message.should == "Error: error message\n" +
|
135
|
-
" This is a multi-line error message.\n" +
|
136
|
-
" It should be properly indented.\n" +
|
137
|
-
" Reason: SubKlass\n" +
|
138
|
-
" original message\n" +
|
139
|
-
" This is a multi-line error message.\n" +
|
140
|
-
" It should be properly indented."
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'uses the original error backtrace' do
|
144
|
-
begin
|
145
|
-
raise subklass.new
|
146
|
-
rescue => err
|
147
|
-
klass.new(nil, err).backtrace.
|
148
|
-
should == err.backtrace
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'reports if original error had no message' do
|
153
|
-
orig_err = subklass.new
|
154
|
-
err = klass.new('error message', orig_err)
|
155
|
-
err.message.should == "Error: error message\n" +
|
156
|
-
" Reason: SubKlass (no message given)"
|
157
|
-
end
|
158
|
-
|
159
|
-
end # context 'when given an original Errors::Error'
|
160
|
-
|
161
|
-
end # context 'when given a message'
|
162
|
-
|
163
|
-
context 'when given no message' do
|
164
|
-
|
165
|
-
it 'strips the module namespace from the default message' do
|
166
|
-
err = klass.new
|
167
|
-
err.message.should == 'Error'
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'when given an original error' do
|
171
|
-
|
172
|
-
it 'uses the original error message' do
|
173
|
-
orig_err = StandardError.new
|
174
|
-
err = klass.new(nil, orig_err)
|
175
|
-
err.message.should == 'Error: StandardError'
|
176
|
-
|
177
|
-
orig_err = StandardError.new('original message')
|
178
|
-
err = klass.new(nil, orig_err)
|
179
|
-
err.message.should == 'Error: StandardError: original message'
|
180
|
-
|
181
|
-
orig_err = StandardError.new(" original message\n" +
|
182
|
-
" This is a multi-line error message.\n" +
|
183
|
-
"It should be properly indented.")
|
184
|
-
err = klass.new(nil, orig_err)
|
185
|
-
err.message.should == "Error: StandardError: original message\n" +
|
186
|
-
" This is a multi-line error message.\n" +
|
187
|
-
" It should be properly indented."
|
188
|
-
end
|
189
|
-
|
190
|
-
end # context 'when given an original error'
|
191
|
-
|
192
|
-
context 'when given an original Errors::Error' do
|
193
|
-
let(:subklass) do
|
194
|
-
class SubKlass < klass; end
|
195
|
-
SubKlass
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'uses the original error message' do
|
199
|
-
orig_err = subklass.new
|
200
|
-
err = klass.new(nil, orig_err)
|
201
|
-
err.message.should == 'Error: SubKlass'
|
202
|
-
|
203
|
-
orig_err = subklass.new('original message')
|
204
|
-
err = klass.new(nil, orig_err)
|
205
|
-
err.message.should == 'Error: SubKlass: original message'
|
206
|
-
|
207
|
-
orig_err = subklass.new(" original message\n" +
|
208
|
-
" This is a multi-line error message.\n" +
|
209
|
-
"It should be properly indented.")
|
210
|
-
err = klass.new(nil, orig_err)
|
211
|
-
err.message.should == "Error: SubKlass: original message\n" +
|
212
|
-
" This is a multi-line error message.\n" +
|
213
|
-
" It should be properly indented."
|
214
|
-
end
|
215
|
-
|
216
|
-
end # context 'when given an original Errors::Error'
|
217
|
-
|
218
|
-
end # context 'when given no message'
|
219
|
-
|
220
|
-
end # describe '#initialize'
|
221
|
-
|
222
|
-
describe '#wrap' do
|
223
|
-
describe 'swaps the parameters to provide a cleaner way to' do
|
224
|
-
|
225
|
-
it 'raise a wrapped error with a message' do
|
226
|
-
orig_err = StandardError.new <<-EOS
|
227
|
-
original message
|
228
|
-
This is a multi-line error message.
|
229
|
-
It should be properly indented.
|
230
|
-
EOS
|
231
|
-
|
232
|
-
expect do
|
233
|
-
raise klass.wrap(orig_err), <<-EOS
|
234
|
-
error message
|
235
|
-
This is a multi-line error message.
|
236
|
-
It should be properly indented.
|
237
|
-
EOS
|
238
|
-
end.to raise_error(klass,
|
239
|
-
"Error: error message\n" +
|
240
|
-
" This is a multi-line error message.\n" +
|
241
|
-
" It should be properly indented.\n" +
|
242
|
-
" Reason: StandardError\n" +
|
243
|
-
" original message\n" +
|
244
|
-
" This is a multi-line error message.\n" +
|
245
|
-
" It should be properly indented."
|
246
|
-
)
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'return a wrapped error with a message' do
|
250
|
-
orig_err = StandardError.new <<-EOS
|
251
|
-
original message
|
252
|
-
This is a multi-line error message.
|
253
|
-
It should be properly indented.
|
254
|
-
EOS
|
255
|
-
|
256
|
-
err = klass.wrap(orig_err, <<-EOS)
|
257
|
-
error message
|
258
|
-
This will wrap the original error
|
259
|
-
and it's message will be given below
|
260
|
-
EOS
|
261
|
-
|
262
|
-
err.message.should ==
|
263
|
-
"Error: error message\n" +
|
264
|
-
" This will wrap the original error\n" +
|
265
|
-
" and it's message will be given below\n" +
|
266
|
-
" Reason: StandardError\n" +
|
267
|
-
" original message\n" +
|
268
|
-
" This is a multi-line error message.\n" +
|
269
|
-
" It should be properly indented."
|
270
|
-
end
|
271
|
-
|
272
|
-
end # describe 'swaps the parameters to provide a cleaner way to'
|
273
|
-
end # describe '#wrap'
|
274
|
-
|
275
|
-
end # describe 'Errors::Error'
|
276
|
-
|
277
|
-
describe 'ErrorHelper' do
|
278
|
-
let(:base) { Backup::Errors }
|
279
|
-
|
280
|
-
it 'dynamically creates namespaces and subclasses of Errors::Error' do
|
281
|
-
Backup::Errors::FooBarError.new.
|
282
|
-
should be_a_kind_of base::Error
|
283
|
-
Backup::Errors::Foo::Bar::Error.new.
|
284
|
-
should be_a_kind_of base::Error
|
285
|
-
end
|
286
|
-
|
287
|
-
context 'new error classes created within new namespaces' do
|
288
|
-
it 'retain the added portion of namespace in their messages' do
|
289
|
-
orig_err = StandardError.new('original message')
|
290
|
-
err = base::FooMod::FooError.new('error message', orig_err)
|
291
|
-
err.message.should ==
|
292
|
-
"FooMod::FooError: error message\n" +
|
293
|
-
" Reason: StandardError\n" +
|
294
|
-
" original message"
|
295
|
-
|
296
|
-
err2 = base::Foo::Bar::Mod::FooBarError.wrap(err, 'foobar message')
|
297
|
-
err2.message.should ==
|
298
|
-
"Foo::Bar::Mod::FooBarError: foobar message\n" +
|
299
|
-
" Reason: FooMod::FooError\n" +
|
300
|
-
" error message\n" +
|
301
|
-
" Reason: StandardError\n" +
|
302
|
-
" original message"
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
end # describe ErrorHelper
|