backup 3.0.27 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +139 -386
  3. data/bin/backup +1 -7
  4. data/lib/backup.rb +3 -9
  5. data/lib/backup/archive.rb +26 -20
  6. data/lib/backup/cleaner.rb +2 -2
  7. data/lib/backup/cli.rb +366 -0
  8. data/lib/backup/compressor/base.rb +2 -2
  9. data/lib/backup/compressor/gzip.rb +35 -1
  10. data/lib/backup/config.rb +1 -2
  11. data/lib/backup/database/base.rb +2 -2
  12. data/lib/backup/database/mongodb.rb +3 -3
  13. data/lib/backup/database/mysql.rb +3 -2
  14. data/lib/backup/database/postgresql.rb +3 -2
  15. data/lib/backup/database/riak.rb +18 -5
  16. data/lib/backup/dependency.rb +144 -93
  17. data/lib/backup/encryptor/base.rb +2 -2
  18. data/lib/backup/logger.rb +108 -110
  19. data/lib/backup/logger/console.rb +51 -0
  20. data/lib/backup/logger/logfile.rb +113 -0
  21. data/lib/backup/logger/syslog.rb +116 -0
  22. data/lib/backup/model.rb +67 -65
  23. data/lib/backup/notifier/base.rb +1 -1
  24. data/lib/backup/notifier/hipchat.rb +1 -1
  25. data/lib/backup/notifier/mail.rb +1 -1
  26. data/lib/backup/notifier/pushover.rb +6 -3
  27. data/lib/backup/packager.rb +4 -4
  28. data/lib/backup/pipeline.rb +17 -3
  29. data/lib/backup/splitter.rb +2 -2
  30. data/lib/backup/storage/base.rb +2 -2
  31. data/lib/backup/storage/cloudfiles.rb +2 -2
  32. data/lib/backup/storage/dropbox.rb +4 -4
  33. data/lib/backup/storage/ftp.rb +2 -2
  34. data/lib/backup/storage/local.rb +2 -2
  35. data/lib/backup/storage/ninefold.rb +2 -2
  36. data/lib/backup/storage/rsync.rb +3 -3
  37. data/lib/backup/storage/s3.rb +2 -2
  38. data/lib/backup/storage/scp.rb +2 -6
  39. data/lib/backup/storage/sftp.rb +2 -5
  40. data/lib/backup/syncer/base.rb +1 -1
  41. data/lib/backup/syncer/cloud/base.rb +15 -8
  42. data/lib/backup/syncer/rsync/local.rb +1 -1
  43. data/lib/backup/syncer/rsync/pull.rb +1 -1
  44. data/lib/backup/syncer/rsync/push.rb +1 -1
  45. data/lib/backup/utilities.rb +211 -0
  46. data/lib/backup/version.rb +1 -1
  47. data/templates/cli/{utility/archive → archive} +4 -8
  48. data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
  49. data/templates/cli/{utility/compressor → compressor}/custom +0 -0
  50. data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
  51. data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
  52. data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
  53. data/templates/cli/config +68 -0
  54. data/templates/cli/{utility/database → database}/mongodb +1 -1
  55. data/templates/cli/{utility/database → database}/mysql +1 -1
  56. data/templates/cli/{utility/database → database}/postgresql +1 -1
  57. data/templates/cli/{utility/database → database}/redis +0 -0
  58. data/templates/cli/database/riak +20 -0
  59. data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
  60. data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
  61. data/templates/cli/{utility/model.erb → model.erb} +4 -4
  62. data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
  63. data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
  64. data/templates/cli/{utility/notifier → notifier}/mail +0 -0
  65. data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
  66. data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
  67. data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
  68. data/templates/cli/{utility/splitter → splitter} +0 -0
  69. data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
  70. data/templates/cli/{utility/storage → storage}/dropbox +0 -0
  71. data/templates/cli/{utility/storage → storage}/ftp +0 -0
  72. data/templates/cli/{utility/storage → storage}/local +0 -0
  73. data/templates/cli/{utility/storage → storage}/ninefold +0 -0
  74. data/templates/cli/{utility/storage → storage}/rsync +0 -0
  75. data/templates/cli/{utility/storage → storage}/s3 +0 -0
  76. data/templates/cli/{utility/storage → storage}/scp +0 -0
  77. data/templates/cli/{utility/storage → storage}/sftp +0 -0
  78. data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
  79. data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
  80. data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
  81. data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
  82. data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
  83. metadata +55 -131
  84. data/.gitignore +0 -8
  85. data/.travis.yml +0 -10
  86. data/Gemfile +0 -28
  87. data/Guardfile +0 -23
  88. data/backup.gemspec +0 -32
  89. data/lib/backup/cli/helpers.rb +0 -93
  90. data/lib/backup/cli/utility.rb +0 -255
  91. data/spec-live/.gitignore +0 -6
  92. data/spec-live/README +0 -7
  93. data/spec-live/backups/config.rb +0 -83
  94. data/spec-live/backups/config.yml.template +0 -46
  95. data/spec-live/backups/models.rb +0 -184
  96. data/spec-live/compressor/custom_spec.rb +0 -30
  97. data/spec-live/compressor/gzip_spec.rb +0 -30
  98. data/spec-live/encryptor/gpg_keys.rb +0 -239
  99. data/spec-live/encryptor/gpg_spec.rb +0 -287
  100. data/spec-live/notifier/mail_spec.rb +0 -121
  101. data/spec-live/spec_helper.rb +0 -151
  102. data/spec-live/storage/dropbox_spec.rb +0 -151
  103. data/spec-live/storage/local_spec.rb +0 -83
  104. data/spec-live/storage/scp_spec.rb +0 -193
  105. data/spec-live/syncer/cloud/s3_spec.rb +0 -124
  106. data/spec/archive_spec.rb +0 -335
  107. data/spec/cleaner_spec.rb +0 -312
  108. data/spec/cli/helpers_spec.rb +0 -301
  109. data/spec/cli/utility_spec.rb +0 -411
  110. data/spec/compressor/base_spec.rb +0 -52
  111. data/spec/compressor/bzip2_spec.rb +0 -217
  112. data/spec/compressor/custom_spec.rb +0 -106
  113. data/spec/compressor/gzip_spec.rb +0 -217
  114. data/spec/compressor/lzma_spec.rb +0 -123
  115. data/spec/compressor/pbzip2_spec.rb +0 -165
  116. data/spec/config_spec.rb +0 -321
  117. data/spec/configuration/helpers_spec.rb +0 -247
  118. data/spec/configuration/store_spec.rb +0 -39
  119. data/spec/configuration_spec.rb +0 -62
  120. data/spec/database/base_spec.rb +0 -63
  121. data/spec/database/mongodb_spec.rb +0 -510
  122. data/spec/database/mysql_spec.rb +0 -411
  123. data/spec/database/postgresql_spec.rb +0 -353
  124. data/spec/database/redis_spec.rb +0 -334
  125. data/spec/database/riak_spec.rb +0 -176
  126. data/spec/dependency_spec.rb +0 -51
  127. data/spec/encryptor/base_spec.rb +0 -40
  128. data/spec/encryptor/gpg_spec.rb +0 -909
  129. data/spec/encryptor/open_ssl_spec.rb +0 -148
  130. data/spec/errors_spec.rb +0 -306
  131. data/spec/logger_spec.rb +0 -367
  132. data/spec/model_spec.rb +0 -666
  133. data/spec/notifier/base_spec.rb +0 -104
  134. data/spec/notifier/campfire_spec.rb +0 -217
  135. data/spec/notifier/hipchat_spec.rb +0 -211
  136. data/spec/notifier/mail_spec.rb +0 -316
  137. data/spec/notifier/prowl_spec.rb +0 -138
  138. data/spec/notifier/pushover_spec.rb +0 -123
  139. data/spec/notifier/twitter_spec.rb +0 -153
  140. data/spec/package_spec.rb +0 -61
  141. data/spec/packager_spec.rb +0 -213
  142. data/spec/pipeline_spec.rb +0 -259
  143. data/spec/spec_helper.rb +0 -60
  144. data/spec/splitter_spec.rb +0 -120
  145. data/spec/storage/base_spec.rb +0 -166
  146. data/spec/storage/cloudfiles_spec.rb +0 -254
  147. data/spec/storage/cycler_spec.rb +0 -247
  148. data/spec/storage/dropbox_spec.rb +0 -480
  149. data/spec/storage/ftp_spec.rb +0 -271
  150. data/spec/storage/local_spec.rb +0 -259
  151. data/spec/storage/ninefold_spec.rb +0 -343
  152. data/spec/storage/rsync_spec.rb +0 -362
  153. data/spec/storage/s3_spec.rb +0 -245
  154. data/spec/storage/scp_spec.rb +0 -233
  155. data/spec/storage/sftp_spec.rb +0 -244
  156. data/spec/syncer/base_spec.rb +0 -109
  157. data/spec/syncer/cloud/base_spec.rb +0 -515
  158. data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
  159. data/spec/syncer/cloud/s3_spec.rb +0 -174
  160. data/spec/syncer/rsync/base_spec.rb +0 -98
  161. data/spec/syncer/rsync/local_spec.rb +0 -149
  162. data/spec/syncer/rsync/pull_spec.rb +0 -98
  163. data/spec/syncer/rsync/push_spec.rb +0 -333
  164. data/spec/version_spec.rb +0 -21
  165. data/templates/cli/utility/config +0 -32
  166. data/templates/cli/utility/database/riak +0 -11
@@ -1,123 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Compressor::Lzma do
6
- before do
7
- Backup::Compressor::Lzma.any_instance.stubs(:utility).returns('lzma')
8
- end
9
-
10
- it 'should be a subclass of Compressor::Base' do
11
- Backup::Compressor::Lzma.
12
- superclass.should == Backup::Compressor::Base
13
- end
14
-
15
- describe '#initialize' do
16
- let(:compressor) { Backup::Compressor::Lzma.new }
17
-
18
- after { Backup::Compressor::Lzma.clear_defaults! }
19
-
20
- it 'should load pre-configured defaults' do
21
- Backup::Compressor::Lzma.any_instance.expects(:load_defaults!)
22
- compressor
23
- end
24
-
25
- context 'when no pre-configured defaults have been set' do
26
- it 'should use default values' do
27
- compressor.best.should be_false
28
- compressor.fast.should be_false
29
- end
30
-
31
- it 'should use the values given' do
32
- compressor = Backup::Compressor::Lzma.new do |c|
33
- c.best = true
34
- c.fast = true
35
- end
36
-
37
- compressor.best.should be_true
38
- compressor.fast.should be_true
39
- end
40
- end # context 'when no pre-configured defaults have been set'
41
-
42
- context 'when pre-configured defaults have been set' do
43
- before do
44
- Backup::Compressor::Lzma.defaults do |c|
45
- c.best = true
46
- c.fast = true
47
- end
48
- end
49
-
50
- it 'should use pre-configured defaults' do
51
- compressor.best.should be_true
52
- compressor.fast.should be_true
53
- end
54
-
55
- it 'should override pre-configured defaults' do
56
- compressor = Backup::Compressor::Lzma.new do |c|
57
- c.best = false
58
- c.fast = false
59
- end
60
-
61
- compressor.best.should be_false
62
- compressor.fast.should be_false
63
- end
64
- end # context 'when pre-configured defaults have been set'
65
- end # describe '#initialize'
66
-
67
- describe '#compress_with' do
68
- before do
69
- Backup::Compressor::Lzma.any_instance.expects(:log!)
70
-
71
- Backup::Logger.expects(:warn).with do |msg|
72
- msg.should match(
73
- /\[DEPRECATION WARNING\]\n Compressor::Lzma is being deprecated/
74
- )
75
- end
76
- end
77
-
78
- it 'should yield with the --best option' do
79
- compressor = Backup::Compressor::Lzma.new do |c|
80
- c.best = true
81
- end
82
-
83
- compressor.compress_with do |cmd, ext|
84
- cmd.should == 'lzma --best'
85
- ext.should == '.lzma'
86
- end
87
- end
88
-
89
- it 'should yield with the --fast option' do
90
- compressor = Backup::Compressor::Lzma.new do |c|
91
- c.fast = true
92
- end
93
-
94
- compressor.compress_with do |cmd, ext|
95
- cmd.should == 'lzma --fast'
96
- ext.should == '.lzma'
97
- end
98
- end
99
-
100
- it 'should prefer the --best option over --fast' do
101
- compressor = Backup::Compressor::Lzma.new do |c|
102
- c.best = true
103
- c.fast = true
104
- end
105
-
106
- compressor.compress_with do |cmd, ext|
107
- cmd.should == 'lzma --best'
108
- ext.should == '.lzma'
109
- end
110
- end
111
-
112
- it 'should yield with no options' do
113
- compressor = Backup::Compressor::Lzma.new
114
-
115
- compressor.compress_with do |cmd, ext|
116
- cmd.should == 'lzma'
117
- ext.should == '.lzma'
118
- end
119
- end
120
-
121
- end # describe '#compress_with'
122
-
123
- end
@@ -1,165 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../../spec_helper.rb', __FILE__)
4
-
5
- describe Backup::Compressor::Pbzip2 do
6
- before do
7
- Backup::Compressor::Pbzip2.any_instance.stubs(:utility).returns('pbzip2')
8
- end
9
-
10
- it 'should be a subclass of Compressor::Base' do
11
- Backup::Compressor::Pbzip2.
12
- superclass.should == Backup::Compressor::Base
13
- end
14
-
15
- describe '#initialize' do
16
- let(:compressor) { Backup::Compressor::Pbzip2.new }
17
-
18
- after { Backup::Compressor::Pbzip2.clear_defaults! }
19
-
20
- it 'should load pre-configured defaults' do
21
- Backup::Compressor::Pbzip2.any_instance.expects(:load_defaults!)
22
- compressor
23
- end
24
-
25
- context 'when no pre-configured defaults have been set' do
26
- it 'should use default values' do
27
- compressor.best.should be_false
28
- compressor.fast.should be_false
29
- compressor.processors.should be_false
30
- end
31
-
32
- it 'should use the values given' do
33
- compressor = Backup::Compressor::Pbzip2.new do |c|
34
- c.best = true
35
- c.fast = true
36
- c.processors = 2
37
- end
38
-
39
- compressor.best.should be_true
40
- compressor.fast.should be_true
41
- compressor.processors.should == 2
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::Compressor::Pbzip2.defaults do |c|
48
- c.best = true
49
- c.fast = true
50
- c.processors = 2
51
- end
52
- end
53
-
54
- it 'should use pre-configured defaults' do
55
- compressor.best.should be_true
56
- compressor.fast.should be_true
57
- compressor.processors.should == 2
58
- end
59
-
60
- it 'should override pre-configured defaults' do
61
- compressor = Backup::Compressor::Pbzip2.new do |c|
62
- c.best = false
63
- c.fast = false
64
- c.processors = 4
65
- end
66
-
67
- compressor.best.should be_false
68
- compressor.fast.should be_false
69
- compressor.processors.should == 4
70
- end
71
- end # context 'when pre-configured defaults have been set'
72
- end # describe '#initialize'
73
-
74
- describe '#compress_with' do
75
- before do
76
- Backup::Compressor::Pbzip2.any_instance.expects(:log!)
77
-
78
- Backup::Logger.expects(:warn).with do |msg|
79
- msg.should match(
80
- /\[DEPRECATION WARNING\]\n Compressor::Pbzip2 is being deprecated/
81
- )
82
- end
83
- end
84
-
85
- it 'should yield with the --best option' do
86
- compressor = Backup::Compressor::Pbzip2.new do |c|
87
- c.best = true
88
- end
89
-
90
- compressor.compress_with do |cmd, ext|
91
- cmd.should == 'pbzip2 --best'
92
- ext.should == '.bz2'
93
- end
94
- end
95
-
96
- it 'should yield with the --fast option' do
97
- compressor = Backup::Compressor::Pbzip2.new do |c|
98
- c.fast = true
99
- end
100
-
101
- compressor.compress_with do |cmd, ext|
102
- cmd.should == 'pbzip2 --fast'
103
- ext.should == '.bz2'
104
- end
105
- end
106
-
107
- it 'should yield with the -p option' do
108
- compressor = Backup::Compressor::Pbzip2.new do |c|
109
- c.processors = 2
110
- end
111
-
112
- compressor.compress_with do |cmd, ext|
113
- cmd.should == 'pbzip2 -p2'
114
- ext.should == '.bz2'
115
- end
116
- end
117
-
118
- it 'should prefer the --best option over --fast' do
119
- compressor = Backup::Compressor::Pbzip2.new do |c|
120
- c.best = true
121
- c.fast = true
122
- end
123
-
124
- compressor.compress_with do |cmd, ext|
125
- cmd.should == 'pbzip2 --best'
126
- ext.should == '.bz2'
127
- end
128
- end
129
-
130
- it 'should yield with the --best and -p options' do
131
- compressor = Backup::Compressor::Pbzip2.new do |c|
132
- c.best = true
133
- c.processors = 2
134
- end
135
-
136
- compressor.compress_with do |cmd, ext|
137
- cmd.should == 'pbzip2 --best -p2'
138
- ext.should == '.bz2'
139
- end
140
- end
141
-
142
- it 'should yield with the --fast and -p options' do
143
- compressor = Backup::Compressor::Pbzip2.new do |c|
144
- c.fast = true
145
- c.processors = 2
146
- end
147
-
148
- compressor.compress_with do |cmd, ext|
149
- cmd.should == 'pbzip2 --fast -p2'
150
- ext.should == '.bz2'
151
- end
152
- end
153
-
154
- it 'should yield with no options' do
155
- compressor = Backup::Compressor::Pbzip2.new
156
-
157
- compressor.compress_with do |cmd, ext|
158
- cmd.should == 'pbzip2'
159
- ext.should == '.bz2'
160
- end
161
- end
162
-
163
- end # describe '#compress_with'
164
-
165
- end
data/spec/config_spec.rb DELETED
@@ -1,321 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../spec_helper.rb', __FILE__)
4
-
5
- describe 'Backup::Config' do
6
- let(:config) { Backup::Config }
7
- before(:all) { config.send(:reset!) }
8
- after(:each) do
9
- config.unstub(:update)
10
- config.unstub(:set_root_path)
11
- config.unstub(:set_path_variable)
12
- config.send(:reset!)
13
- end
14
-
15
- describe '#update' do
16
- let(:default_root_path) { config.root_path }
17
-
18
- context 'when a root_path is given' do
19
- it 'should use #set_root_path to set the new root_path' do
20
- config.expects(:set_root_path).with('a/path')
21
-
22
- config.update(:root_path => 'a/path')
23
- end
24
-
25
- it 'should set all paths using the new root_path' do
26
- config.expects(:set_root_path).with('path').returns('/root/path')
27
- Backup::Config::DEFAULTS.each do |key, val|
28
- config.expects(:set_path_variable).with(key, nil, val, '/root/path')
29
- end
30
-
31
- config.update(:root_path => 'path')
32
- end
33
- end # context 'when a root_path is given'
34
-
35
- context 'when a root_path is not given' do
36
- it 'should set all paths without using a root_path' do
37
- Backup::Config::DEFAULTS.each do |key, val|
38
- config.expects(:set_path_variable).with(key, nil, val, false)
39
- end
40
-
41
- config.update
42
- end
43
- end # context 'when a root_path is not given'
44
-
45
- end # describe '#update'
46
-
47
- describe '#load_config!' do
48
- context 'when @config_file exists' do
49
- before do
50
- File.expects(:exist?).with(config.config_file).returns(true)
51
- end
52
-
53
- it 'should load the config file' do
54
- File.expects(:read).with(config.config_file).returns(:file_contents)
55
- config.expects(:module_eval).with(:file_contents, config.config_file)
56
-
57
- expect do
58
- config.load_config!
59
- end.not_to raise_error
60
- end
61
- end
62
-
63
- context 'when @config_file does not exist' do
64
- before do
65
- File.expects(:exist?).returns(false)
66
- end
67
-
68
- it 'should raise an error' do
69
- File.expects(:read).never
70
- config.expects(:module_eval).never
71
-
72
- expect do
73
- config.load_config!
74
- end.to raise_error {|err|
75
- err.should be_an_instance_of Backup::Errors::Config::NotFoundError
76
- err.message.should match(
77
- /Could not find configuration file: '#{config.config_file}'/
78
- )
79
- }
80
- end
81
- end
82
- end # describe '#load_config!'
83
-
84
- describe '#set_root_path' do
85
-
86
- context 'when the given path == @root_path' do
87
- it 'should return @root_path without requiring the path to exist' do
88
- File.expects(:directory?).never
89
- expect do
90
- config.send(:set_root_path, config.root_path).
91
- should == config.root_path
92
- end.not_to raise_error
93
- end
94
- end
95
-
96
- context 'when the given path exists' do
97
- it 'should set and return the @root_path' do
98
- expect do
99
- config.send(:set_root_path, Dir.pwd).should == Dir.pwd
100
- end.not_to raise_error
101
- config.root_path.should == Dir.pwd
102
- end
103
-
104
- it 'should expand relative paths' do
105
- expect do
106
- config.send(:set_root_path, '').should == Dir.pwd
107
- end.not_to raise_error
108
- config.root_path.should == Dir.pwd
109
- end
110
- end
111
-
112
- context 'when the given path does not exist' do
113
- it 'should raise an error' do
114
- path = File.expand_path('foo')
115
- expect do
116
- config.send(:set_root_path, 'foo')
117
- end.to raise_error {|err|
118
- err.should be_an_instance_of Backup::Errors::Config::NotFoundError
119
- err.message.should match(/Root Path Not Found/)
120
- err.message.should match(/Path was: #{ path }/)
121
- }
122
- end
123
- end
124
-
125
- end # describe '#set_root_path'
126
-
127
- describe '#set_path_variable' do
128
- after do
129
- if config.instance_variable_defined?(:@var)
130
- config.send(:remove_instance_variable, :@var)
131
- end
132
- end
133
-
134
- context 'when a path is given' do
135
- context 'when the given path is an absolute path' do
136
- it 'should always use the given path' do
137
- path = File.expand_path('foo')
138
-
139
- config.send(:set_path_variable, 'var', path, 'none', '/root/path')
140
- config.instance_variable_get(:@var).should == path
141
-
142
- config.send(:set_path_variable, 'var', path, 'none', nil)
143
- config.instance_variable_get(:@var).should == path
144
- end
145
- end
146
-
147
- context 'when the given path is a relative path' do
148
- context 'when a root_path is given' do
149
- it 'should append the path to the root_path' do
150
- config.send(:set_path_variable, 'var', 'foo', 'none', '/root/path')
151
- config.instance_variable_get(:@var).should == '/root/path/foo'
152
- end
153
- end
154
- context 'when a root_path is not given' do
155
- it 'should expand the path' do
156
- path = File.expand_path('foo')
157
-
158
- config.send(:set_path_variable, 'var', 'foo', 'none', false)
159
- config.instance_variable_get(:@var).should == path
160
- end
161
- end
162
- end
163
- end # context 'when a path is given'
164
-
165
- context 'when no path is given' do
166
- context 'when a root_path is given' do
167
- it 'should use the root_path with the given ending' do
168
- config.send(:set_path_variable, 'var', nil, 'ending', '/root/path')
169
- config.instance_variable_get(:@var).should == '/root/path/ending'
170
- end
171
- end
172
- context 'when a root_path is not given' do
173
- it 'should do nothing' do
174
- config.send(:set_path_variable, 'var', nil, 'ending', false)
175
- config.instance_variable_defined?(:@var).should be_false
176
- end
177
- end
178
- end # context 'when no path is given'
179
-
180
- end # describe '#set_path_variable'
181
-
182
- describe '#reset!' do
183
- before do
184
- @env_user = ENV['USER']
185
- @env_home = ENV['HOME']
186
- end
187
-
188
- after do
189
- ENV['USER'] = @env_user
190
- ENV['HOME'] = @env_home
191
- end
192
-
193
- it 'should be called to set variables when module is loaded' do
194
- # just to avoid 'already initialized constant' warnings
195
- config.constants.each {|const| config.send(:remove_const, const) }
196
-
197
- expected = config.instance_variables.sort.map(&:to_sym) - [:@mocha]
198
- config.instance_variables.each do |var|
199
- config.send(:remove_instance_variable, var)
200
- end
201
- config.instance_variables.should be_empty
202
-
203
- load File.expand_path('../../lib/backup/config.rb', __FILE__)
204
- config.instance_variables.sort.map(&:to_sym).should == expected
205
- end
206
-
207
- context 'when setting @user' do
208
- context 'when ENV["USER"] is set' do
209
- before { ENV['USER'] = 'test' }
210
-
211
- it 'should set value for @user to ENV["USER"]' do
212
- config.send(:reset!)
213
- config.user.should == 'test'
214
- end
215
- end
216
-
217
- context 'when ENV["USER"] is not set' do
218
- before { ENV.delete('USER') }
219
-
220
- it 'should set value using the user login name' do
221
- config.send(:reset!)
222
- config.user.should == Etc.getpwuid.name
223
- end
224
- end
225
- end # context 'when setting @user'
226
-
227
- context 'when setting @root_path' do
228
- context 'when ENV["HOME"] is set' do
229
- before { ENV['HOME'] = 'test/home/dir' }
230
-
231
- it 'should set value using ENV["HOME"]' do
232
- config.send(:reset!)
233
- config.root_path.should ==
234
- File.join(File.expand_path('test/home/dir'),'Backup')
235
- end
236
- end
237
-
238
- context 'when ENV["HOME"] is not set' do
239
- before { ENV.delete('HOME') }
240
-
241
- it 'should set value using $PWD' do
242
- config.send(:reset!)
243
- config.root_path.should == File.expand_path('Backup')
244
- end
245
- end
246
- end # context 'when setting @root_path'
247
-
248
- context 'when setting other path variables' do
249
- before { ENV['HOME'] = 'test/home/dir' }
250
-
251
- it 'should use #update' do
252
- config.expects(:update).with(
253
- :root_path => File.join(File.expand_path('test/home/dir'),'Backup')
254
- )
255
- config.send(:reset!)
256
- end
257
- end
258
-
259
- end # describe '#reset!'
260
-
261
- describe '#add_dsl_constants!' do
262
- it 'should be called when the module is loaded' do
263
- config.constants.each {|const| config.send(:remove_const, const) }
264
- config.constants.should be_empty
265
-
266
- load File.expand_path('../../lib/backup/config.rb', __FILE__)
267
-
268
- Backup::Config.const_defined?('MySQL').should be_true
269
- Backup::Config.const_defined?('RSync').should be_true
270
- Backup::Config::RSync.const_defined?('Local').should be_true
271
- end
272
- end # describe '#add_dsl_constants!'
273
-
274
- describe '#create_modules' do
275
- module TestScope; end
276
-
277
- context 'when given an array of constant names' do
278
- it 'should create modules for the given scope' do
279
- config.send(:create_modules, TestScope, ['Foo', 'Bar'])
280
- TestScope.const_defined?('Foo').should be_true
281
- TestScope.const_defined?('Bar').should be_true
282
- TestScope::Foo.class.should == Module
283
- TestScope::Bar.class.should == Module
284
- end
285
- end
286
-
287
- context 'when the given array contains Hash values' do
288
- it 'should create deeply nested modules' do
289
- config.send(
290
- :create_modules,
291
- TestScope,
292
- [ 'FooBar', {
293
- :LevelA => [ 'NameA', {
294
- :LevelB => ['NameB']
295
- } ]
296
- } ]
297
- )
298
- TestScope.const_defined?('FooBar').should be_true
299
- TestScope.const_defined?('LevelA').should be_true
300
- TestScope::LevelA.const_defined?('NameA').should be_true
301
- TestScope::LevelA.const_defined?('LevelB').should be_true
302
- TestScope::LevelA::LevelB.const_defined?('NameB').should be_true
303
- end
304
- end
305
- end
306
-
307
- describe 'Backup.const_missing' do
308
- it 'should warn if Backup::CONFIG_FILE is referenced from an older config.rb' do
309
- Backup::Logger.expects(:warn)
310
- expect do
311
- Backup.const_get('CONFIG_FILE').should == Backup::Config.config_file
312
- end.not_to raise_error
313
- end
314
-
315
- it 'should still handle other missing constants' do
316
- expect do
317
- Backup.const_get('FOO')
318
- end.to raise_error(NameError, 'uninitialized constant Backup::FOO')
319
- end
320
- end
321
- end