geoffreywiseman-prune 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +3 -0
- data/lib/prune/archiver.rb +1 -1
- data/lib/prune/meta.rb +2 -2
- data/spec/archiver_spec.rb +24 -24
- data/spec/cli_spec.rb +22 -22
- data/spec/configurer_spec.rb +14 -14
- data/spec/grouper_spec.rb +7 -7
- data/spec/pruner_spec.rb +66 -66
- data/spec/retention_spec.rb +42 -42
- data/spec/spec_helper.rb +2 -2
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: daed96c1d85b82b3b7ebada4575e27659c27049d
|
|
4
|
+
data.tar.gz: 78ef1ce3951e62e29f1cc8dd8de98373d0d16765
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7acfa1fda4d6b9984f4d66c8e62066f8658cc0fa43521645918b5fe98cd6fb076ff55b1d8af0cc82c56057d79289cc3fe0bd1ff06917bcbd4ad43a24551dc950
|
|
7
|
+
data.tar.gz: e7178a263ab4dac01b8aa8b71035e4c1cc259a5328ff3fc49617735d86f5ce80b33e0f1e97f24ce52251a205b42a0f6adce39696198b80f478912ae9790ca0a0
|
data/Rakefile
CHANGED
data/lib/prune/archiver.rb
CHANGED
data/lib/prune/meta.rb
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
# @author Geoffrey Wiseman
|
|
6
6
|
module Prune
|
|
7
7
|
# The version of the prune gem and all the associated code.
|
|
8
|
-
VERSION = Gem::Version.new '1.3.
|
|
8
|
+
VERSION = Gem::Version.new '1.3.2'
|
|
9
9
|
|
|
10
10
|
# The release date associated with the version
|
|
11
|
-
RELEASE_DATE = '
|
|
11
|
+
RELEASE_DATE = '2018-01-31'
|
|
12
12
|
end
|
data/spec/archiver_spec.rb
CHANGED
|
@@ -15,18 +15,18 @@ describe Prune::Archiver do
|
|
|
15
15
|
subject { Prune::Archiver.new( nil, '/mysql', true ) }
|
|
16
16
|
|
|
17
17
|
it "should have #{DESTINATION} destination" do
|
|
18
|
-
subject.destination.
|
|
18
|
+
expect(subject.destination).to eq( DESTINATION )
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should create #{DESTINATION} if does not exist" do
|
|
22
|
-
File.
|
|
23
|
-
Dir.
|
|
22
|
+
allow(File).to receive( :exists? ).with( DESTINATION ) { false }
|
|
23
|
+
expect(Dir).to receive( :mkdir ).with( DESTINATION )
|
|
24
24
|
subject.make_destination_dir
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should not attempt to create #{DESTINATION} if it exists" do
|
|
28
|
-
File.
|
|
29
|
-
Dir.
|
|
28
|
+
allow(File).to receive( :exists? ).with( DESTINATION ) { true }
|
|
29
|
+
expect(Dir).not_to receive( :mkdir )
|
|
30
30
|
subject.make_destination_dir
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -36,19 +36,19 @@ describe Prune::Archiver do
|
|
|
36
36
|
it "should write new archive file in #{DESTINATION} if none exists" do
|
|
37
37
|
|
|
38
38
|
# Destination Exists
|
|
39
|
-
File.
|
|
39
|
+
allow(File).to receive( :exists? ).with( DESTINATION ) { true }
|
|
40
40
|
|
|
41
41
|
# Archive File Exists
|
|
42
|
-
File.
|
|
42
|
+
allow(File).to receive( :exists? ).with( ARCHIVE_FILE ) { false }
|
|
43
43
|
|
|
44
44
|
# Create Zip File
|
|
45
45
|
archive_file = double "file"
|
|
46
46
|
gz = double "GzipWriter"
|
|
47
47
|
paths = [ "/mysql/a", "/mysql/b", "/mysql/c" ]
|
|
48
|
-
File.
|
|
49
|
-
Zlib::GzipWriter.
|
|
50
|
-
Minitar.
|
|
51
|
-
File.
|
|
48
|
+
allow(File).to receive( :open ).with( ARCHIVE_FILE, 'wb' ) { archive_file }
|
|
49
|
+
allow(Zlib::GzipWriter).to receive( :new ) { gz }
|
|
50
|
+
expect(Minitar).to receive( :pack ).with( paths, gz )
|
|
51
|
+
expect(File).to receive( :delete ).with( *paths )
|
|
52
52
|
|
|
53
53
|
subject.archive "May-2011", ["a", "b", "c"]
|
|
54
54
|
end
|
|
@@ -56,35 +56,35 @@ describe Prune::Archiver do
|
|
|
56
56
|
it "should add to existing archive file if it exists" do
|
|
57
57
|
|
|
58
58
|
# Destination Exists
|
|
59
|
-
File.
|
|
59
|
+
allow(File).to receive( :exists? ).with( DESTINATION ) { true }
|
|
60
60
|
|
|
61
61
|
# Archive File Exists
|
|
62
|
-
File.
|
|
62
|
+
allow(File).to receive( :exists? ).with( ARCHIVE_FILE ) { true }
|
|
63
63
|
|
|
64
64
|
# Should Create Temp Dir
|
|
65
65
|
tmpdir = "/tmp"
|
|
66
|
-
Dir.
|
|
66
|
+
allow(Dir).to receive( :mktmpdir ).and_yield( tmpdir )
|
|
67
67
|
|
|
68
68
|
# Should Extract Contents
|
|
69
69
|
archive_file = double "archive file"
|
|
70
|
-
File.
|
|
70
|
+
allow(File).to receive( :open ).with( ARCHIVE_FILE, 'rb' ) { archive_file }
|
|
71
71
|
gzr = double "GzipReader"
|
|
72
|
-
Zlib::GzipReader.
|
|
73
|
-
Minitar.
|
|
74
|
-
Dir.
|
|
72
|
+
allow(Zlib::GzipReader).to receive( :new ) { gzr }
|
|
73
|
+
expect(Minitar).to receive( :unpack ).with( gzr, tmpdir )
|
|
74
|
+
expect(Dir).to receive( :entries ).with( tmpdir ) { ["c", "d"] }
|
|
75
75
|
extracted_paths = [ "/tmp/c", "/tmp/d" ]
|
|
76
|
-
extracted_paths.each { |path| File.
|
|
76
|
+
extracted_paths.each { |path| allow(File).to receive( :directory? ).with( path ).and_return( false ) }
|
|
77
77
|
|
|
78
78
|
# Should Create Final Archive
|
|
79
|
-
File.
|
|
79
|
+
allow(File).to receive( :open ).with( ARCHIVE_FILE, 'wb' ) { archive_file }
|
|
80
80
|
gzw = double "GzipWriter"
|
|
81
|
-
Zlib::GzipWriter.
|
|
81
|
+
allow(Zlib::GzipWriter).to receive( :new ) { gzw }
|
|
82
82
|
original_paths = [ "/mysql/a", "/mysql/b" ]
|
|
83
83
|
combined_paths = extracted_paths + original_paths
|
|
84
|
-
Minitar.
|
|
84
|
+
expect(Minitar).to receive( :pack ).with( combined_paths, gzw )
|
|
85
85
|
|
|
86
86
|
# Delete Files
|
|
87
|
-
File.
|
|
87
|
+
expect(File).to receive( :delete ).with( *original_paths )
|
|
88
88
|
|
|
89
89
|
# Go
|
|
90
90
|
subject.archive "May-2011", ["a", "b"]
|
|
@@ -97,7 +97,7 @@ describe Prune::Archiver do
|
|
|
97
97
|
subject { Prune::Archiver.new( '/mysql/archives', '/mysql', true ) }
|
|
98
98
|
|
|
99
99
|
it "should use the explicit destination" do
|
|
100
|
-
subject.destination.
|
|
100
|
+
expect(subject.destination).to eq( '/mysql/archives' )
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
end
|
data/spec/cli_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ describe Prune::CommandLineInterface do
|
|
|
10
10
|
|
|
11
11
|
before(:each) do
|
|
12
12
|
@messages = []
|
|
13
|
-
$stdout.
|
|
13
|
+
allow($stdout).to receive( :write ) { |message| @messages << message }
|
|
14
14
|
|
|
15
15
|
@pruner = double( "pruner" )
|
|
16
16
|
end
|
|
@@ -20,7 +20,7 @@ describe Prune::CommandLineInterface do
|
|
|
20
20
|
it "should print help" do
|
|
21
21
|
ARGV.clear
|
|
22
22
|
Prune::CommandLineInterface::parse_and_run
|
|
23
|
-
@messages.
|
|
23
|
+
expect(@messages).to include_match( USAGE_TEXT )
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
end
|
|
@@ -30,17 +30,17 @@ describe Prune::CommandLineInterface do
|
|
|
30
30
|
|
|
31
31
|
before(:each) do
|
|
32
32
|
ARGV.clear.push( PATH )
|
|
33
|
-
@pruner.
|
|
33
|
+
allow(@pruner).to receive(:prune)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should call prune with path" do
|
|
37
|
-
Prune::Pruner.
|
|
38
|
-
@pruner.
|
|
37
|
+
allow(Prune::Pruner).to receive( :new ) { @pruner }
|
|
38
|
+
expect(@pruner).to receive( :prune ).with( PATH )
|
|
39
39
|
Prune::CommandLineInterface::parse_and_run
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "should create pruner with defaults" do
|
|
43
|
-
Prune::Pruner.
|
|
43
|
+
allow(Prune::Pruner).to receive( :new ).with( Prune::CommandLineInterface::DEFAULT_OPTIONS ) { @pruner }
|
|
44
44
|
Prune::CommandLineInterface::parse_and_run
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -89,8 +89,8 @@ describe Prune::CommandLineInterface do
|
|
|
89
89
|
describe "and a --config argument" do
|
|
90
90
|
it "should set the configure option to true" do
|
|
91
91
|
configurer = double( "Configurer" )
|
|
92
|
-
Prune::Configurer.
|
|
93
|
-
configurer.
|
|
92
|
+
expect(Prune::Configurer).to receive( :new ).with( PATH, hash_including( :configure => true ) ).and_return( configurer )
|
|
93
|
+
expect(configurer).to receive( :configure )
|
|
94
94
|
ARGV.push( "--config" )
|
|
95
95
|
Prune::CommandLineInterface::parse_and_run
|
|
96
96
|
end
|
|
@@ -103,9 +103,9 @@ describe Prune::CommandLineInterface do
|
|
|
103
103
|
|
|
104
104
|
describe "with no folder name" do
|
|
105
105
|
it "should print a parsing error" do
|
|
106
|
-
$stderr.
|
|
106
|
+
allow($stderr).to receive( :print ) { |message| @messages << message }
|
|
107
107
|
Prune::CommandLineInterface::parse_and_run
|
|
108
|
-
@messages.
|
|
108
|
+
expect(@messages).to include_match( /missing argument: -a/ )
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
@@ -123,9 +123,9 @@ describe Prune::CommandLineInterface do
|
|
|
123
123
|
|
|
124
124
|
describe "with no folder name" do
|
|
125
125
|
it "should print a parsing error" do
|
|
126
|
-
$stderr.
|
|
126
|
+
allow($stderr).to receive( :print ) { |message| @messages << message }
|
|
127
127
|
Prune::CommandLineInterface::parse_and_run
|
|
128
|
-
@messages.
|
|
128
|
+
expect(@messages).to include_match( /missing argument: --archive-folder/ )
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -144,11 +144,11 @@ describe Prune::CommandLineInterface do
|
|
|
144
144
|
|
|
145
145
|
it "should print help" do
|
|
146
146
|
Prune::CommandLineInterface::parse_and_run
|
|
147
|
-
@messages.
|
|
147
|
+
expect(@messages).to include_match( USAGE_TEXT )
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "should not invoke prune" do
|
|
151
|
-
@pruner.
|
|
151
|
+
expect(@pruner).not_to receive( :prune )
|
|
152
152
|
Prune::CommandLineInterface::parse_and_run
|
|
153
153
|
end
|
|
154
154
|
|
|
@@ -162,11 +162,11 @@ describe Prune::CommandLineInterface do
|
|
|
162
162
|
|
|
163
163
|
it "should print help" do
|
|
164
164
|
Prune::CommandLineInterface::parse_and_run
|
|
165
|
-
@messages.
|
|
165
|
+
expect(@messages).to include_match( USAGE_TEXT )
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
it "should not invoke prune" do
|
|
169
|
-
@pruner.
|
|
169
|
+
expect(@pruner).not_to receive( :prune )
|
|
170
170
|
Prune::CommandLineInterface::parse_and_run
|
|
171
171
|
end
|
|
172
172
|
|
|
@@ -175,9 +175,9 @@ describe Prune::CommandLineInterface do
|
|
|
175
175
|
describe "and an unknown argument" do
|
|
176
176
|
it "should print a parsing error" do
|
|
177
177
|
ARGV.push "--unknown-argument"
|
|
178
|
-
$stderr.
|
|
178
|
+
allow($stderr).to receive( :print ) { |message| @messages << message }
|
|
179
179
|
Prune::CommandLineInterface::parse_and_run
|
|
180
|
-
@messages.
|
|
180
|
+
expect(@messages).to include_match( /invalid option/ )
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
183
|
|
|
@@ -187,13 +187,13 @@ describe Prune::CommandLineInterface do
|
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
it "should print version number" do
|
|
190
|
-
$stderr.
|
|
190
|
+
allow($stderr).to receive( :print ) { |message| @messages << message }
|
|
191
191
|
Prune::CommandLineInterface::parse_and_run
|
|
192
|
-
@messages.
|
|
192
|
+
expect(@messages).to include_match( /Prune #{Prune::VERSION}/ )
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
it "should not invoke prune" do
|
|
196
|
-
@pruner.
|
|
196
|
+
expect(@pruner).not_to receive( :prune )
|
|
197
197
|
Prune::CommandLineInterface::parse_and_run
|
|
198
198
|
end
|
|
199
199
|
|
|
@@ -206,7 +206,7 @@ describe Prune::CommandLineInterface do
|
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
def assert_arg_to_option( arg, *options )
|
|
209
|
-
Prune::Pruner.
|
|
209
|
+
expect(Prune::Pruner).to receive( :new ).with( hash_including( *options ) ).and_return( @pruner )
|
|
210
210
|
ARGV.push( arg )
|
|
211
211
|
Prune::CommandLineInterface::parse_and_run
|
|
212
212
|
end
|
data/spec/configurer_spec.rb
CHANGED
|
@@ -16,7 +16,7 @@ describe Prune::Configurer do
|
|
|
16
16
|
context "with no config file present" do
|
|
17
17
|
it "should copy core retention policy if no config file" do
|
|
18
18
|
surpress_messages
|
|
19
|
-
FileUtils.
|
|
19
|
+
expect(FileUtils).to receive(:cp).with( match(/default_retention.rb/), CONFIG_FILE )
|
|
20
20
|
subject.configure
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -24,46 +24,46 @@ describe Prune::Configurer do
|
|
|
24
24
|
context "with a directory in place of the config file" do
|
|
25
25
|
before do
|
|
26
26
|
stub_messages
|
|
27
|
-
File.
|
|
27
|
+
allow(File).to receive( :directory? ) { true }
|
|
28
28
|
end
|
|
29
29
|
it "should warn that it can't create file" do
|
|
30
30
|
subject.configure
|
|
31
|
-
@messages.
|
|
31
|
+
expect(@messages).to include_match( /cannot create or edit configuration/ )
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
context "with config file that canot be written" do
|
|
36
36
|
before do
|
|
37
|
-
File.
|
|
38
|
-
File.
|
|
39
|
-
File.
|
|
37
|
+
allow(File).to receive( :directory? ).with( CONFIG_FILE ) { false }
|
|
38
|
+
allow(File).to receive( :file? ).with( CONFIG_FILE ) { true }
|
|
39
|
+
allow(File).to receive( :writable? ).with( CONFIG_FILE ) { false }
|
|
40
40
|
stub_messages
|
|
41
41
|
end
|
|
42
42
|
it "should warn that cannot edit config" do
|
|
43
43
|
subject.configure
|
|
44
|
-
@messages.
|
|
44
|
+
expect(@messages).to include_match( /cannot edit configuration/ )
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
context "with a writeable config file" do
|
|
49
49
|
|
|
50
50
|
before do
|
|
51
|
-
File.
|
|
52
|
-
File.
|
|
53
|
-
File.
|
|
51
|
+
allow(File).to receive( :directory? ).with( CONFIG_FILE ) { false }
|
|
52
|
+
allow(File).to receive( :file? ).with( CONFIG_FILE ) { true }
|
|
53
|
+
allow(File).to receive( :writable? ).with( CONFIG_FILE ) { true }
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "should warn if no editor defined" do
|
|
57
57
|
stub_messages
|
|
58
58
|
subject.configure
|
|
59
|
-
@messages.
|
|
59
|
+
expect(@messages).to include_match( /No editor defined/ )
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
context "with EDITOR environment variable defined" do
|
|
63
63
|
it "should invoke editor" do
|
|
64
64
|
surpress_messages
|
|
65
65
|
ENV['EDITOR']='ed'
|
|
66
|
-
subject.
|
|
66
|
+
expect(subject).to receive( :system ).with( "ed #{CONFIG_FILE}" ).and_return( true )
|
|
67
67
|
subject.configure
|
|
68
68
|
end
|
|
69
69
|
end
|
|
@@ -73,7 +73,7 @@ describe Prune::Configurer do
|
|
|
73
73
|
surpress_messages
|
|
74
74
|
ENV['VISUAL']='gedit'
|
|
75
75
|
ENV['EDITOR']='ed'
|
|
76
|
-
subject.
|
|
76
|
+
expect(subject).to receive( :system ).with( "gedit #{CONFIG_FILE}" ).and_return( true )
|
|
77
77
|
subject.configure
|
|
78
78
|
end
|
|
79
79
|
end
|
|
@@ -82,7 +82,7 @@ describe Prune::Configurer do
|
|
|
82
82
|
it "should invoke visual editor if defined in VISUAL" do
|
|
83
83
|
surpress_messages
|
|
84
84
|
ENV['VISUAL']='gedit'
|
|
85
|
-
subject.
|
|
85
|
+
expect(subject).to receive( :system ).with( "gedit #{CONFIG_FILE}" ).and_return( true )
|
|
86
86
|
subject.configure
|
|
87
87
|
end
|
|
88
88
|
end
|
data/spec/grouper_spec.rb
CHANGED
|
@@ -14,7 +14,7 @@ describe "Prune::Grouper" do
|
|
|
14
14
|
context "w/o files" do
|
|
15
15
|
|
|
16
16
|
it "should not archive" do
|
|
17
|
-
@archiver.
|
|
17
|
+
expect(@archiver).not_to receive( :archive )
|
|
18
18
|
@grouper.group( GROUP_PATH, [] ).archive
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -24,26 +24,26 @@ describe "Prune::Grouper" do
|
|
|
24
24
|
|
|
25
25
|
it "should archive files" do
|
|
26
26
|
files = mock_files( Date.new(2011,01,01) )
|
|
27
|
-
@archiver.
|
|
27
|
+
expect(@archiver).to receive( :archive )
|
|
28
28
|
@grouper.group( GROUP_PATH, files ).archive
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "should specify month and year" do
|
|
32
32
|
files = mock_files( Date.new(2008,03,01) )
|
|
33
|
-
@archiver.
|
|
33
|
+
expect(@archiver).to receive( :archive ).with( "Mar-2008", files )
|
|
34
34
|
@grouper.group( GROUP_PATH, files ).archive
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should combine files with same month/year" do
|
|
38
38
|
files = mock_files( Date.new(2008,03,01), Date.new(2008,03,02) )
|
|
39
|
-
@archiver.
|
|
39
|
+
expect(@archiver).to receive( :archive ).with( "Mar-2008", files )
|
|
40
40
|
@grouper.group( GROUP_PATH, files ).archive
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "should not combine files with same month, different year" do
|
|
44
44
|
files = mock_files( Date.new(2008,03,01), Date.new(2009,03,01) )
|
|
45
|
-
@archiver.
|
|
46
|
-
@archiver.
|
|
45
|
+
expect(@archiver).to receive( :archive ).with( "Mar-2008", [files.first] )
|
|
46
|
+
expect(@archiver).to receive( :archive ).with( "Mar-2009", [files.last] )
|
|
47
47
|
@grouper.group( GROUP_PATH, files ).archive
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -54,7 +54,7 @@ describe "Prune::Grouper" do
|
|
|
54
54
|
dates.map do |item|
|
|
55
55
|
month_name = Date::ABBR_MONTHNAMES[item.month]
|
|
56
56
|
file_name = "file-#{month_name}-#{item.year}.sql"
|
|
57
|
-
File.
|
|
57
|
+
allow(File).to receive( :mtime ).with( "#{GROUP_PATH}/#{file_name}" ) { item }
|
|
58
58
|
files << file_name
|
|
59
59
|
end
|
|
60
60
|
return files;
|
data/spec/pruner_spec.rb
CHANGED
|
@@ -10,8 +10,8 @@ describe Prune::Pruner do
|
|
|
10
10
|
before( :each ) do
|
|
11
11
|
@categories = [ Prune::Category.new( "Unmatched Files", :retain, true ) ]
|
|
12
12
|
@retention_policy = double( "RetentionPolicy" )
|
|
13
|
-
@retention_policy.
|
|
14
|
-
Prune::RetentionPolicy.
|
|
13
|
+
allow(@retention_policy).to receive( :categories ) { @categories }
|
|
14
|
+
allow(Prune::RetentionPolicy).to receive( :new ) { @retention_policy }
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
context "w/o prompt" do
|
|
@@ -20,9 +20,9 @@ describe Prune::Pruner do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should not attempt to process folder that does not exist" do
|
|
23
|
-
File.
|
|
24
|
-
Dir.
|
|
25
|
-
$stdout.
|
|
23
|
+
allow(File).to receive( :exists? ).with( PRUNE_PATH ) { false }
|
|
24
|
+
expect(Dir).not_to receive( :foreach )
|
|
25
|
+
expect($stdout).to receive( :write ).with( /ERROR: Cannot find folder/ )
|
|
26
26
|
subject.prune( PRUNE_PATH )
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -35,19 +35,19 @@ describe Prune::Pruner do
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should not invoke the retention policy" do
|
|
38
|
-
@retention_policy.
|
|
38
|
+
expect(@retention_policy).not_to receive( :categorize )
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "should print 'Analyzing #{PRUNE_PATH}'" do
|
|
42
|
-
@messages.
|
|
42
|
+
expect(@messages).to include("Analyzing '#{PRUNE_PATH}':\n")
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "should say no action was required" do
|
|
46
|
-
@messages.
|
|
46
|
+
expect(@messages).to include("No actions necessary.\n")
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "should say no files were analyzed" do
|
|
50
|
-
@messages.
|
|
50
|
+
expect(@messages).to include_match( /0 file\(s\) analyzed/ )
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
@@ -61,19 +61,19 @@ describe Prune::Pruner do
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should not invoke the retention policy" do
|
|
64
|
-
@retention_policy.
|
|
64
|
+
expect(@retention_policy).not_to receive( :categorize )
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should print 'Analyzing #{PRUNE_PATH}'" do
|
|
68
|
-
@messages.
|
|
68
|
+
expect(@messages).to include("Analyzing '#{PRUNE_PATH}':\n")
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "should say no action was required" do
|
|
72
|
-
@messages.
|
|
72
|
+
expect(@messages).to include("No actions necessary.\n")
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "should say no files were analyzed" do
|
|
76
|
-
@messages.
|
|
76
|
+
expect(@messages).to include_match( /0 file\(s\) analyzed/ )
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
end
|
|
@@ -88,16 +88,16 @@ describe Prune::Pruner do
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "should categorize each file in modified order" do
|
|
91
|
-
@retention_policy.
|
|
92
|
-
@retention_policy.
|
|
93
|
-
@retention_policy.
|
|
91
|
+
expect(@retention_policy).to receive( :categorize ).with( 'alpha.txt' ).ordered
|
|
92
|
+
expect(@retention_policy).to receive( :categorize ).with( 'beta.txt' ).ordered
|
|
93
|
+
expect(@retention_policy).to receive( :categorize ).with( 'gamma.txt' ).ordered
|
|
94
94
|
subject.prune PRUNE_PATH
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "should say three files were analyzed" do
|
|
98
98
|
@retention_policy.as_null_object
|
|
99
99
|
subject.prune PRUNE_PATH
|
|
100
|
-
@messages.
|
|
100
|
+
expect(@messages).to include_match( /3 file\(s\) analyzed/ )
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
end
|
|
@@ -111,27 +111,27 @@ describe Prune::Pruner do
|
|
|
111
111
|
stub_files FILENAME
|
|
112
112
|
|
|
113
113
|
category = double( category )
|
|
114
|
-
category.
|
|
115
|
-
category.
|
|
116
|
-
category.
|
|
117
|
-
@retention_policy.
|
|
114
|
+
allow(category).to receive( :description ) { "Old" }
|
|
115
|
+
allow(category).to receive( :action ) { :remove }
|
|
116
|
+
allow(category).to receive( :quiet? ) { false }
|
|
117
|
+
expect(@retention_policy).to receive( :categorize ).with( FILENAME ) { category }
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "should delete file" do
|
|
121
|
-
FileUtils.
|
|
121
|
+
expect(FileUtils).to receive( :remove_entry ).with( File.join( PRUNE_PATH, FILENAME ), true ) { 1 }
|
|
122
122
|
subject.prune PRUNE_PATH
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
it "should display file deleted message" do
|
|
126
|
-
FileUtils.
|
|
126
|
+
expect(FileUtils).to receive( :remove_entry ).with( File.join( PRUNE_PATH, FILENAME ), true ) { 1 }
|
|
127
127
|
subject.prune PRUNE_PATH
|
|
128
|
-
@messages.
|
|
128
|
+
expect(@messages).to include_match( /1 file\(s\) deleted/ )
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
it "should display failed deletion mesage" do
|
|
132
|
-
FileUtils.
|
|
132
|
+
expect(FileUtils).to receive( :remove_entry ).with( File.join( PRUNE_PATH, FILENAME ), true ) { 0 }
|
|
133
133
|
subject.prune PRUNE_PATH
|
|
134
|
-
@messages.
|
|
134
|
+
expect(@messages).to include_match( /0 file\(s\) deleted, 1 file\(s\) could not be deleted/ )
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
end
|
|
@@ -144,17 +144,17 @@ describe Prune::Pruner do
|
|
|
144
144
|
stub_messages
|
|
145
145
|
|
|
146
146
|
category = double( "category" )
|
|
147
|
-
category.
|
|
148
|
-
category.
|
|
149
|
-
category.
|
|
147
|
+
allow(category).to receive( :action ) { :archive }
|
|
148
|
+
allow(category).to receive( :description ) { "Archive" }
|
|
149
|
+
allow(category).to receive( :quiet? ) { false }
|
|
150
150
|
|
|
151
|
-
@retention_policy.
|
|
151
|
+
allow(@retention_policy).to receive( :categories ) { [ category ]}
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "should indicate no archive necessary" do
|
|
155
155
|
subject.prune PRUNE_PATH
|
|
156
156
|
puts "Messages: #{@messages}"
|
|
157
|
-
@messages.
|
|
157
|
+
expect(@messages).to include_match( /No files categorized for archival/ )
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
end
|
|
@@ -168,17 +168,17 @@ describe Prune::Pruner do
|
|
|
168
168
|
stub_messages
|
|
169
169
|
|
|
170
170
|
category = double( "category" )
|
|
171
|
-
@retention_policy.
|
|
172
|
-
category.
|
|
173
|
-
category.
|
|
174
|
-
category.
|
|
171
|
+
allow(@retention_policy).to receive( :categorize ) { category }
|
|
172
|
+
allow(category).to receive( :action ) { :archive }
|
|
173
|
+
allow(category).to receive( :description ) { "Ancient" }
|
|
174
|
+
allow(category).to receive( :quiet? ) { false }
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
it "should archive files in groups" do
|
|
178
178
|
grouper = double( "Grouper" )
|
|
179
|
-
Prune::Grouper.
|
|
180
|
-
grouper.
|
|
181
|
-
grouper.
|
|
179
|
+
allow(Prune::Grouper).to receive( :new ) { grouper }
|
|
180
|
+
expect(grouper).to receive( :group ).with( PRUNE_PATH, files )
|
|
181
|
+
expect(grouper).to receive( :archive ) { "2 Archives created." }
|
|
182
182
|
|
|
183
183
|
subject.prune PRUNE_PATH
|
|
184
184
|
end
|
|
@@ -186,7 +186,7 @@ describe Prune::Pruner do
|
|
|
186
186
|
it "should display message if archive option disabled" do
|
|
187
187
|
subject.options[:archive] = false
|
|
188
188
|
subject.prune PRUNE_PATH
|
|
189
|
-
@messages.
|
|
189
|
+
expect(@messages).to include_match( /Archive option disabled/ )
|
|
190
190
|
end
|
|
191
191
|
end
|
|
192
192
|
|
|
@@ -206,17 +206,17 @@ describe Prune::Pruner do
|
|
|
206
206
|
|
|
207
207
|
it "should display empty categories" do
|
|
208
208
|
subject.display_categories( { Prune::Category.new( "Empty Category", :retain ) => [] } )
|
|
209
|
-
@messages.
|
|
209
|
+
expect(@messages).to include_match( /Empty Category/ )
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
it "should display quiet categories" do
|
|
213
213
|
subject.display_categories( { Prune::Category.new( "Quiet Category", :retain, true ) => [ 'quiet.txt' ] } )
|
|
214
|
-
@messages.
|
|
214
|
+
expect(@messages).to include_match( /Quiet Category/ )
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
it "should display categories with files" do
|
|
218
218
|
subject.display_categories( { Prune::Category.new( "Normal Category", :retain ) => [ 'normal.txt' ] } )
|
|
219
|
-
@messages.
|
|
219
|
+
expect(@messages).to include_match( /Normal Category/ )
|
|
220
220
|
end
|
|
221
221
|
end
|
|
222
222
|
|
|
@@ -228,17 +228,17 @@ describe Prune::Pruner do
|
|
|
228
228
|
|
|
229
229
|
it "should not display empty categories" do
|
|
230
230
|
subject.display_categories( { Prune::Category.new( "Empty Category", :retain, true ) => [] } )
|
|
231
|
-
@messages.
|
|
231
|
+
expect(@messages).not_to include_match( /Empty Category/ )
|
|
232
232
|
end
|
|
233
233
|
|
|
234
234
|
it "should not display quiet categories" do
|
|
235
235
|
subject.display_categories( { Prune::Category.new( "Quiet Category", :retain, true ) => [ 'shhh.txt' ] } )
|
|
236
|
-
@messages.
|
|
236
|
+
expect(@messages).not_to include_match( /Quiet Category/ )
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
it "should display categories with files" do
|
|
240
240
|
subject.display_categories( { Prune::Category.new( "Normal Category", :retain ) => [ 'normal.txt' ] } )
|
|
241
|
-
@messages.
|
|
241
|
+
expect(@messages).to include_match( /Normal Category/ )
|
|
242
242
|
end
|
|
243
243
|
|
|
244
244
|
end
|
|
@@ -251,76 +251,76 @@ describe Prune::Pruner do
|
|
|
251
251
|
|
|
252
252
|
it "should interpret 'Y' as true" do
|
|
253
253
|
expect_prompt_with_response( "Y\n")
|
|
254
|
-
subject.prompt.
|
|
254
|
+
expect(subject.prompt).to be_truthy
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
it "should interpret 'Y ' as true" do
|
|
258
258
|
expect_prompt_with_response("Y \n")
|
|
259
|
-
subject.prompt.
|
|
259
|
+
expect(subject.prompt).to be_truthy
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
it "should interpret ' Y' as true" do
|
|
263
263
|
expect_prompt_with_response(" Y\n")
|
|
264
|
-
subject.prompt.
|
|
264
|
+
expect(subject.prompt).to be_truthy
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
it "should interpret ' Y ' as true" do
|
|
268
268
|
expect_prompt_with_response(" Y \n")
|
|
269
|
-
subject.prompt.
|
|
269
|
+
expect(subject.prompt).to be_truthy
|
|
270
270
|
end
|
|
271
271
|
|
|
272
272
|
it "should interpret 'y' as true" do
|
|
273
273
|
expect_prompt_with_response("y\n")
|
|
274
|
-
subject.prompt.
|
|
274
|
+
expect(subject.prompt).to be_truthy
|
|
275
275
|
end
|
|
276
276
|
|
|
277
277
|
it "should interpret 'yes' as true" do
|
|
278
278
|
expect_prompt_with_response("yes\n")
|
|
279
|
-
subject.prompt.
|
|
279
|
+
expect(subject.prompt).to be_truthy
|
|
280
280
|
end
|
|
281
281
|
|
|
282
282
|
it "should interpret 'no' as false" do
|
|
283
283
|
expect_prompt_with_response("no\n")
|
|
284
|
-
subject.prompt.
|
|
284
|
+
expect(subject.prompt).to be_falsey
|
|
285
285
|
end
|
|
286
286
|
|
|
287
287
|
it "should interpret 'n' as false" do
|
|
288
288
|
expect_prompt_with_response("n\n")
|
|
289
|
-
subject.prompt.
|
|
289
|
+
expect(subject.prompt).to be_falsey
|
|
290
290
|
end
|
|
291
291
|
|
|
292
292
|
it "should interpret 'N' as false" do
|
|
293
293
|
expect_prompt_with_response("N\n")
|
|
294
|
-
subject.prompt.
|
|
294
|
+
expect(subject.prompt).to be_falsey
|
|
295
295
|
end
|
|
296
296
|
|
|
297
297
|
it "should interpret 'q' as false" do
|
|
298
298
|
expect_prompt_with_response("q\n")
|
|
299
|
-
subject.prompt.
|
|
299
|
+
expect(subject.prompt).to be_falsey
|
|
300
300
|
end
|
|
301
301
|
|
|
302
302
|
def expect_prompt_with_response( response )
|
|
303
|
-
$stdout.
|
|
304
|
-
STDIN.
|
|
303
|
+
expect($stdout).to receive( :write ).with( /Proceed?/ )
|
|
304
|
+
allow(STDIN).to receive(:gets) { response }
|
|
305
305
|
end
|
|
306
306
|
|
|
307
307
|
end
|
|
308
308
|
|
|
309
309
|
def stub_files( files = nil )
|
|
310
|
-
File.
|
|
311
|
-
File.
|
|
310
|
+
allow(File).to receive( :exists? ).with( PRUNE_PATH ) { true }
|
|
311
|
+
allow(File).to receive( :directory? ).with( PRUNE_PATH ) { true }
|
|
312
312
|
case files
|
|
313
313
|
when nil
|
|
314
|
-
Dir.
|
|
314
|
+
allow(Dir).to receive( :entries ).with( PRUNE_PATH ) { Array.new }
|
|
315
315
|
when String
|
|
316
|
-
subject.
|
|
317
|
-
Dir.
|
|
316
|
+
allow(subject).to receive(:test).with( ?M, File.join( PRUNE_PATH, files ) ) { Time.now }
|
|
317
|
+
allow(Dir).to receive( :entries ).with( PRUNE_PATH ) { [ files ] }
|
|
318
318
|
when Array
|
|
319
|
-
files.each_index { |index| subject.
|
|
320
|
-
Dir.
|
|
319
|
+
files.each_index { |index| allow(subject).to receive(:test).with( ?M, File.join( PRUNE_PATH, files[index] ) ) { index } }
|
|
320
|
+
allow(Dir).to receive( :entries ).with( PRUNE_PATH ) { files }
|
|
321
321
|
when Hash
|
|
322
|
-
files.each_key { |key| subject.
|
|
323
|
-
Dir.
|
|
322
|
+
files.each_key { |key| allow(subject).to receive(:test).with( ?M, File.join( PRUNE_PATH, key ) ) { files[key] } }
|
|
323
|
+
allow(Dir).to receive( :entries ).with( PRUNE_PATH ) { files.keys }
|
|
324
324
|
else
|
|
325
325
|
raise "Don't know how to stub files for #{files.class}"
|
|
326
326
|
end
|
data/spec/retention_spec.rb
CHANGED
|
@@ -21,28 +21,28 @@ describe Prune::RetentionPolicy do
|
|
|
21
21
|
|
|
22
22
|
it "should return categories in dsl order" do
|
|
23
23
|
cats = subject.categories
|
|
24
|
-
cats.shift.description.
|
|
25
|
-
cats.shift.description.
|
|
26
|
-
cats.shift.description.
|
|
27
|
-
cats.shift.description.
|
|
28
|
-
cats.shift.description.
|
|
29
|
-
cats.
|
|
24
|
+
expect(cats.shift.description).to include( "Ignoring directories" )
|
|
25
|
+
expect(cats.shift.description).to include( "from the Last Two Weeks" )
|
|
26
|
+
expect(cats.shift.description).to include( "Retaining 'Friday'" )
|
|
27
|
+
expect(cats.shift.description).to include( "Removing 'Non-Friday'" )
|
|
28
|
+
expect(cats.shift.description).to include( "Archiving" )
|
|
29
|
+
expect(cats).to be_empty
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
describe "analyzing a directory" do
|
|
33
33
|
let( :dircat ) do
|
|
34
|
-
File.
|
|
35
|
-
File.
|
|
34
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { true }
|
|
35
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { Time.now }
|
|
36
36
|
subject.categorize( SOURCE_FILE )
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
it "should be categorized as 'Ignoring directories'" do
|
|
41
|
-
dircat.description.
|
|
41
|
+
expect(dircat.description).to eq( "Ignoring directories" )
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "should invoke action :ignore" do
|
|
45
|
-
dircat.action.
|
|
45
|
+
expect(dircat.action).to eq( :ignore )
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -51,35 +51,35 @@ describe Prune::RetentionPolicy do
|
|
|
51
51
|
describe "created yesterday" do
|
|
52
52
|
|
|
53
53
|
let( :yestercat ) do
|
|
54
|
-
File.
|
|
55
|
-
File.
|
|
54
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { false }
|
|
55
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { Time.now - DAY }
|
|
56
56
|
subject.categorize( SOURCE_FILE )
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "should be categorized as '... Last Two Weeks'" do
|
|
60
|
-
yestercat.description.
|
|
60
|
+
expect(yestercat.description).to include( 'Last Two Weeks' )
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should invoke action :retain" do
|
|
64
|
-
yestercat.action.
|
|
64
|
+
expect(yestercat.action).to eq( :retain )
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
describe "created three weeks ago, wednesday" do
|
|
69
69
|
|
|
70
70
|
let( :weeksago ) do
|
|
71
|
-
File.
|
|
72
|
-
File.
|
|
71
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { false }
|
|
72
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { weeks_ago( 3, 'Wed' ) }
|
|
73
73
|
subject.categorize( SOURCE_FILE )
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "should be described as 'Older than Two Weeks' and 'Non-Friday'" do
|
|
77
|
-
weeksago.description.
|
|
78
|
-
weeksago.description.
|
|
77
|
+
expect(weeksago.description).to include 'Non-Friday'
|
|
78
|
+
expect(weeksago.description).to include 'Older than Two Weeks'
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "should invoke action :remove" do
|
|
82
|
-
weeksago.action.
|
|
82
|
+
expect(weeksago.action).to eq( :remove )
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
end
|
|
@@ -87,18 +87,18 @@ describe Prune::RetentionPolicy do
|
|
|
87
87
|
describe "created three weeks ago, friday" do
|
|
88
88
|
|
|
89
89
|
let( :weeksagofriday ) do
|
|
90
|
-
File.
|
|
91
|
-
File.
|
|
90
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { false }
|
|
91
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { weeks_ago( 3, 'Fri' ) }
|
|
92
92
|
subject.categorize( SOURCE_FILE )
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it "should be described as 'Friday files', 'Older than Two Weeks'" do
|
|
96
|
-
weeksagofriday.description.
|
|
97
|
-
weeksagofriday.description.
|
|
96
|
+
expect(weeksagofriday.description).to include( "'Friday' files" )
|
|
97
|
+
expect(weeksagofriday.description).to include( 'Older than Two Weeks' )
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "should invoke action :remove" do
|
|
101
|
-
weeksagofriday.action.
|
|
101
|
+
expect(weeksagofriday.action).to eq( :retain )
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
end
|
|
@@ -106,17 +106,17 @@ describe Prune::RetentionPolicy do
|
|
|
106
106
|
describe "created three months ago, friday" do
|
|
107
107
|
|
|
108
108
|
let( :oldfriday ) do
|
|
109
|
-
File.
|
|
110
|
-
File.
|
|
109
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { false }
|
|
110
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { weeks_ago( 12, 'Fri' ) }
|
|
111
111
|
subject.categorize( SOURCE_FILE )
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it "should be described as 'Older than Two Months'" do
|
|
115
|
-
oldfriday.description.
|
|
115
|
+
expect(oldfriday.description).to include( 'Older than Two Months' )
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "should invoke action :archive" do
|
|
119
|
-
oldfriday.action.
|
|
119
|
+
expect(oldfriday.action).to eq( :archive )
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
end
|
|
@@ -124,18 +124,18 @@ describe Prune::RetentionPolicy do
|
|
|
124
124
|
describe "created three months ago, wednesday" do
|
|
125
125
|
|
|
126
126
|
let( :oldwednesday ) do
|
|
127
|
-
File.
|
|
128
|
-
File.
|
|
127
|
+
allow(File).to receive( :directory? ).with( SOURCE_PATH ) { false }
|
|
128
|
+
allow(File).to receive( :mtime ).with( SOURCE_PATH ) { weeks_ago( 12, 'Wed' ) }
|
|
129
129
|
subject.categorize( SOURCE_FILE )
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
it "should be described as 'Non-Friday files', 'Older than Two Weeks'" do
|
|
133
|
-
oldwednesday.description.
|
|
134
|
-
oldwednesday.description.
|
|
133
|
+
expect(oldwednesday.description).to include( "'Non-Friday' files" )
|
|
134
|
+
expect(oldwednesday.description).to include( "Older than Two Weeks" )
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
it "should invoke action :remove" do
|
|
138
|
-
oldwednesday.action.
|
|
138
|
+
expect(oldwednesday.action).to eq( :remove )
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
end
|
|
@@ -170,33 +170,33 @@ describe Prune::RetentionPolicy do
|
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
it "should ignore directories" do
|
|
173
|
-
subject.categorize( "." ).description.
|
|
173
|
+
expect(subject.categorize( "." ).description).to eq( "Ignoring" )
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
it "should ignore files not matching pattern" do
|
|
177
|
-
File.
|
|
178
|
-
subject.categorize( 'readme.txt' ).description.
|
|
177
|
+
allow(File).to receive(:file?) { true }
|
|
178
|
+
expect(subject.categorize( 'readme.txt' ).description).to eq( 'Ignoring' )
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
describe "with a file named with 20101001" do
|
|
182
182
|
before do
|
|
183
|
-
File.
|
|
184
|
-
File.
|
|
183
|
+
allow(File).to receive(:directory?) { false }
|
|
184
|
+
allow(File).to receive(:file?) { true }
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
it "should categorize as 2010" do
|
|
188
|
-
subject.categorize( 'mysql-prod-20101001.sql.gz' ).description.
|
|
188
|
+
expect(subject.categorize( 'mysql-prod-20101001.sql.gz' ).description).to eq( '2010' )
|
|
189
189
|
end
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
describe "with a file named with 20110215" do
|
|
193
193
|
before do
|
|
194
|
-
File.
|
|
195
|
-
File.
|
|
194
|
+
allow(File).to receive(:directory?) { false }
|
|
195
|
+
allow(File).to receive(:file?) { true }
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
it "should categorize as 2011" do
|
|
199
|
-
subject.categorize( 'subversion-20110215.tar.gz' ).description.
|
|
199
|
+
expect(subject.categorize( 'subversion-20110215.tar.gz' ).description).to eq( '2011' )
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,11 +3,11 @@ SimpleCov.start
|
|
|
3
3
|
|
|
4
4
|
def stub_messages
|
|
5
5
|
@messages = []
|
|
6
|
-
$stdout.
|
|
6
|
+
allow($stdout).to receive( :write ) { |message| @messages << message }
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def surpress_messages
|
|
10
|
-
$stdout.
|
|
10
|
+
allow($stdout).to receive( :write )
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
RSpec::Matchers.define :include_match do |expected|
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: geoffreywiseman-prune
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Geoffrey Wiseman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitar
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
19
|
+
version: '0.6'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
26
|
+
version: '0.6'
|
|
27
27
|
description: Prune is meant to analyze a folder full of files, run them against a
|
|
28
28
|
retention policy and decide which to keep, which to remove and which to archive.
|
|
29
29
|
It is extensible and embeddable.
|
|
@@ -54,7 +54,8 @@ files:
|
|
|
54
54
|
- spec/retention_spec.rb
|
|
55
55
|
- spec/spec_helper.rb
|
|
56
56
|
homepage: http://geoffreywiseman.github.com/prune
|
|
57
|
-
licenses:
|
|
57
|
+
licenses:
|
|
58
|
+
- UNLICENSE
|
|
58
59
|
metadata: {}
|
|
59
60
|
post_install_message:
|
|
60
61
|
rdoc_options: []
|