maid 0.9.0.alpha.2 → 0.10.0.pre.alpha.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/.act-env +1 -0
- data/.act-secrets.example +2 -0
- data/.github/workflows/coverage.yml +29 -0
- data/.github/workflows/lint.yml +24 -0
- data/.github/workflows/release.yml +62 -0
- data/.github/workflows/test.yml +2 -2
- data/.gitignore +2 -0
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +372 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -1
- data/Guardfile +31 -4
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/Vagrantfile +2 -2
- data/lib/maid/app.rb +48 -51
- data/lib/maid/maid.rb +38 -38
- data/lib/maid/numeric_extensions.rb +26 -25
- data/lib/maid/platform.rb +1 -1
- data/lib/maid/rake/task.rb +1 -1
- data/lib/maid/repeat.rb +8 -8
- data/lib/maid/rule_container.rb +3 -3
- data/lib/maid/rules.sample.rb +17 -17
- data/lib/maid/tools.rb +142 -127
- data/lib/maid/trash_migration.rb +4 -4
- data/lib/maid/user_agent.rb +2 -2
- data/lib/maid/version.rb +5 -2
- data/lib/maid/watch.rb +10 -12
- data/maid.gemspec +36 -18
- data/spec/dependency_spec.rb +9 -8
- data/spec/lib/maid/app_spec.rb +31 -23
- data/spec/lib/maid/maid_spec.rb +74 -52
- data/spec/lib/maid/numeric_extensions_spec.rb +1 -1
- data/spec/lib/maid/platform_spec.rb +1 -1
- data/spec/lib/maid/rake/single_rule_spec.rb +11 -6
- data/spec/lib/maid/rake/task_spec.rb +3 -5
- data/spec/lib/maid/rule_spec.rb +1 -1
- data/spec/lib/maid/tools_spec.rb +94 -92
- data/spec/lib/maid/trash_migration_spec.rb +12 -11
- data/spec/lib/maid/user_agent_spec.rb +5 -4
- data/spec/lib/maid_spec.rb +1 -1
- data/spec/spec_helper.rb +19 -3
- metadata +177 -61
data/lib/maid/watch.rb
CHANGED
@@ -5,33 +5,31 @@ class Maid::Watch
|
|
5
5
|
|
6
6
|
attr_reader :path, :listener, :logger
|
7
7
|
|
8
|
-
def initialize(maid, path, options = {}, &
|
8
|
+
def initialize(maid, path, options = {}, &block)
|
9
9
|
@maid = maid
|
10
10
|
|
11
11
|
if options.nil? || options.empty?
|
12
12
|
@lazy = true
|
13
13
|
@options = { wait_for_delay: 10,
|
14
|
-
ignore: Maid::Downloading.downloading_file_regexps }
|
14
|
+
ignore: Maid::Downloading.downloading_file_regexps, }
|
15
15
|
else
|
16
|
-
@lazy = options.delete(:lazy) { |
|
16
|
+
@lazy = options.delete(:lazy) { |_key| true }
|
17
17
|
@options = options
|
18
18
|
end
|
19
19
|
|
20
20
|
@logger = maid.logger # TODO: Maybe it's better to create seperate loggers?
|
21
21
|
@path = File.expand_path(path)
|
22
|
-
initialize_rules(&
|
22
|
+
initialize_rules(&block)
|
23
23
|
end
|
24
24
|
|
25
25
|
def run
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
@listener.start
|
26
|
+
return if rules.empty?
|
27
|
+
|
28
|
+
@listener = Listen.to(path, @options) do |modified, added, removed|
|
29
|
+
follow_rules(modified, added, removed) if !@lazy || added.any? || removed.any?
|
34
30
|
end
|
31
|
+
|
32
|
+
@listener.start
|
35
33
|
end
|
36
34
|
|
37
35
|
def stop
|
data/maid.gemspec
CHANGED
@@ -1,34 +1,43 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
1
|
+
$:.push File.expand_path('lib', __dir__)
|
3
2
|
require 'maid/version'
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = 'maid'
|
7
6
|
s.version = Maid::VERSION
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ['Benjamin Oakes']
|
10
|
-
s.email =
|
8
|
+
s.authors = ['Benjamin Oakes', 'Coaxial']
|
9
|
+
s.email = ['hello@benjaminoakes.com', 'c+rubygems@64b.it']
|
11
10
|
s.license = 'GPLv2'
|
12
|
-
s.homepage = 'http://github.com/
|
11
|
+
s.homepage = 'http://github.com/maid/maid'
|
13
12
|
s.summary = Maid::SUMMARY
|
14
13
|
s.description = s.summary
|
14
|
+
s.files = Dir['lib/**/*.rb'] + Dir['bin/maid']
|
15
|
+
s.metadata = {
|
16
|
+
'bug_tracker_uri' => 'https://github.com/maid/maid/issues',
|
17
|
+
'changelog_uri' => 'https://github.com/maid/maid/blob/master/CHANGELOG.md',
|
18
|
+
'documentation_uri' => 'https://github.com/maid/maid/blob/master/README.md',
|
19
|
+
'source_code_uri' => 'https://github.com/maid/maid',
|
20
|
+
'wiki_uri' => 'https://github.com/maid/maid/wiki',
|
21
|
+
'rubygems_mfa_required' => 'true',
|
22
|
+
}
|
15
23
|
|
16
24
|
s.rubyforge_project = 'maid'
|
17
25
|
|
18
26
|
s.required_ruby_version = '>= 2.7.0'
|
19
27
|
|
20
28
|
# Strategy: if possible, use ranges (so there are fewer chances of version conflicts)
|
21
|
-
s.add_dependency('escape', '>= 0.0.1', '< 0.1.0') # Used for better Ruby 1.8.7 support, could be replaced with `Shellwords`
|
22
|
-
s.add_dependency('thor', '~> 1.2.1')
|
23
29
|
s.add_dependency('deprecated', '~> 3.0.0')
|
24
30
|
s.add_dependency('dimensions', '>= 1.0.0', '< 2.0')
|
31
|
+
# Used for better Ruby 1.8.7 support, could be replaced with `Shellwords`
|
32
|
+
s.add_dependency('escape', '>= 0.0.1', '< 0.1.0')
|
33
|
+
s.add_dependency('exifr', '~> 1.3.10')
|
34
|
+
s.add_dependency('geocoder', '~> 1.8.1')
|
35
|
+
s.add_dependency('listen', '~> 3.8.0')
|
25
36
|
s.add_dependency('mime-types', '~> 3.0', '< 4.0')
|
26
37
|
s.add_dependency('rubyzip', '~> 2.3.2')
|
27
|
-
s.add_dependency('xdg', '~> 2.2.3') # previous versions had bugs
|
28
|
-
s.add_dependency('listen', '~> 3.8.0')
|
29
38
|
s.add_dependency('rufus-scheduler', '~> 3.8.2')
|
30
|
-
s.add_dependency('
|
31
|
-
s.add_dependency('
|
39
|
+
s.add_dependency('thor', '~> 1.2.1')
|
40
|
+
s.add_dependency('xdg', '~> 2.2.3') # previous versions had bugs
|
32
41
|
|
33
42
|
# TODO: use one of these two gems instead of `mdfind`. **But** They have to work on Linux as well.
|
34
43
|
#
|
@@ -37,25 +46,34 @@ Gem::Specification.new do |s|
|
|
37
46
|
|
38
47
|
# Strategy: specific versions (since they're just for development)
|
39
48
|
s.add_development_dependency('fakefs', '~> 2.4.0')
|
40
|
-
s.add_development_dependency('
|
41
|
-
s.add_development_dependency('guard
|
49
|
+
s.add_development_dependency('fuubar')
|
50
|
+
s.add_development_dependency('guard', '~> 2.18.0')
|
51
|
+
s.add_development_dependency('guard-bundler', '~> 3.0.1')
|
52
|
+
s.add_development_dependency('guard-rspec', '~> 4.7.3')
|
53
|
+
s.add_development_dependency('guard-rubocop')
|
54
|
+
s.add_development_dependency('pry-byebug')
|
42
55
|
s.add_development_dependency('rake', '~> 13.0.6')
|
43
56
|
s.add_development_dependency('redcarpet', '~> 3.6.0') # Soft dependency of `yard`
|
44
57
|
s.add_development_dependency('rspec', '~> 3.12.0')
|
58
|
+
s.add_development_dependency('rubocop')
|
59
|
+
s.add_development_dependency('rubocop-rake')
|
60
|
+
s.add_development_dependency('rubocop-rspec')
|
61
|
+
s.add_development_dependency('simplecov')
|
45
62
|
s.add_development_dependency('timecop', '~> 0.9.6')
|
46
63
|
s.add_development_dependency('yard', '>= 0.9.11')
|
47
|
-
s.add_development_dependency('pry-byebug')
|
48
64
|
|
49
65
|
# In Vagrant, polling won't cross over the OS boundary if you develop in the host OS but run your tests in the
|
50
66
|
# guest. One way around this is to force polling instead:
|
51
67
|
#
|
52
68
|
# bundle exec guard --force-polling
|
53
69
|
#
|
54
|
-
s.add_development_dependency('rb-inotify', '~> 0.10.1')
|
55
70
|
s.add_development_dependency('rb-fsevent', '~> 0.11.2')
|
71
|
+
s.add_development_dependency('rb-inotify', '~> 0.10.1')
|
56
72
|
|
57
73
|
s.files = `git ls-files -z`.split("\0")
|
58
|
-
s.
|
59
|
-
s.
|
60
|
-
|
74
|
+
s.executables = `git ls-files -z -- bin/*`.split("\0").map { |f| File.basename(f) }
|
75
|
+
s.require_paths = %w[lib]
|
76
|
+
|
77
|
+
s.post_install_message = "🙏 Thank you for installing Maid, we hope it's " \
|
78
|
+
"useful to you! Visit #{s.homepage} to report issues or contribute code."
|
61
79
|
end
|
data/spec/dependency_spec.rb
CHANGED
@@ -20,12 +20,13 @@ describe 'Dependency expectations' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe Logger do
|
23
|
-
# Depending on the situation, `Logger` might have been overwritten to have
|
23
|
+
# Depending on the situation, `Logger` might have been overwritten to have
|
24
|
+
# a different interface. (I'm looking at you, Rails.)
|
24
25
|
it 'logs with the expected interface' do
|
25
26
|
io = StringIO.new
|
26
27
|
logger = Logger.new(io)
|
27
28
|
logger.info('my message')
|
28
|
-
logger.formatter =
|
29
|
+
logger.formatter = ->(_, _, _, msg) { msg }
|
29
30
|
expect(io.string).to match(/my message/)
|
30
31
|
end
|
31
32
|
end
|
@@ -68,28 +69,28 @@ describe 'Dependency expectations' do
|
|
68
69
|
|
69
70
|
describe Zip::File do
|
70
71
|
it 'makes entries available with #entries' do
|
71
|
-
Zip::File.open("
|
72
|
-
expect(zip_file.entries.map { |entry| entry.name }).to match_array(%w
|
72
|
+
Zip::File.open("#{@file_fixtures_path}/foo.zip") do |zip_file|
|
73
|
+
expect(zip_file.entries.map { |entry| entry.name }).to match_array(%w[README.txt foo.exe subdir/anything.txt])
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'supports UTF-8 filenames' do
|
77
78
|
# Filename is a Japanese character
|
78
|
-
Zip::File.open("
|
79
|
-
expect(zip_file.entries.map { |entry| entry.name }).to eq(%w
|
79
|
+
Zip::File.open("#{@file_fixtures_path}/\343\201\225.zip") do |zip_file|
|
80
|
+
expect(zip_file.entries.map { |entry| entry.name }).to eq(%w[anything.txt])
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
84
85
|
describe Dimensions do
|
85
86
|
it 'returns dimensions as an array' do
|
86
|
-
expect(Dimensions.dimensions("
|
87
|
+
expect(Dimensions.dimensions("#{@file_fixtures_path}/sydney.jpg")).to eq([100, 75])
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
90
91
|
describe EXIFR::JPEG do
|
91
92
|
it 'returns latitude and longitude' do
|
92
|
-
gps = EXIFR::JPEG.new("
|
93
|
+
gps = EXIFR::JPEG.new("#{@file_fixtures_path}/sydney.jpg").gps
|
93
94
|
expect([gps.latitude, gps.longitude]).to eq([-33.85608611111111, 151.219925])
|
94
95
|
end
|
95
96
|
end
|
data/spec/lib/maid/app_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'stringio'
|
3
3
|
|
4
|
+
# FIXME: this clobbers rspec's output in the console. out.truncate(0) flushes
|
5
|
+
# the StringIO object but fails the test. Maybe stubbing Kernel.warn and
|
6
|
+
# Kernel.info would silence the output?
|
7
|
+
# Something like spec/lib/maid/maid_spec.rb:5 and :172
|
4
8
|
def capture_stdout
|
5
9
|
out = StringIO.new
|
6
10
|
$stdout = out
|
@@ -10,6 +14,10 @@ ensure
|
|
10
14
|
$stdout = STDOUT
|
11
15
|
end
|
12
16
|
|
17
|
+
# FIXME: this clobbers rspec's output in the console. out.truncate(0) flushes
|
18
|
+
# the StringIO object but fails the test. Maybe stubbing Kernel.warn and
|
19
|
+
# Kernel.info would silence the output?
|
20
|
+
# Something like spec/lib/maid/maid_spec.rb:5 and :172
|
13
21
|
def capture_stderr
|
14
22
|
out = StringIO.new
|
15
23
|
$stderr = out
|
@@ -21,33 +29,33 @@ end
|
|
21
29
|
|
22
30
|
module Maid
|
23
31
|
describe App, '#clean' do
|
24
|
-
|
25
32
|
before do
|
26
33
|
@app = App.new
|
27
|
-
@app.
|
28
|
-
@app.
|
34
|
+
allow(@app).to receive(:maid_options)
|
35
|
+
allow(@app).to receive(:say)
|
29
36
|
|
30
|
-
TrashMigration.
|
37
|
+
allow(TrashMigration).to receive(:needed?).and_return(false)
|
31
38
|
|
32
|
-
# NOTE: It's pretty important that this is stubbed, unless you want your
|
39
|
+
# NOTE: It's pretty important that this is stubbed, unless you want your
|
40
|
+
# rules to be run over and over when you test!
|
33
41
|
@maid = double('Maid')
|
34
|
-
@maid.
|
35
|
-
@maid.
|
36
|
-
@maid.
|
37
|
-
Maid.
|
42
|
+
allow(@maid).to receive(:clean)
|
43
|
+
allow(@maid).to receive(:log_device)
|
44
|
+
allow(@maid).to receive(:load_rules)
|
45
|
+
allow(Maid).to receive(:new).and_return(@maid)
|
38
46
|
end
|
39
47
|
|
40
48
|
it 'makes a new Maid with the options' do
|
41
|
-
opts = { :
|
42
|
-
@app.
|
49
|
+
opts = { foo: 'bar' }
|
50
|
+
allow(@app).to receive(:maid_options).and_return(opts)
|
43
51
|
expect(Maid).to receive(:new).with(opts).and_return(@maid)
|
44
52
|
@app.clean
|
45
53
|
end
|
46
54
|
|
47
|
-
it 'cleans when --force is specified' do
|
55
|
+
it 'cleans when --force is specified' do
|
48
56
|
expect(@maid).to receive(:clean)
|
49
57
|
App.start(['clean', '--force'])
|
50
|
-
end
|
58
|
+
end
|
51
59
|
|
52
60
|
it 'issues deprecation notice when called without option, but still clean' do
|
53
61
|
expect(@maid).to receive(:clean).twice
|
@@ -94,13 +102,13 @@ module Maid
|
|
94
102
|
# FIXME: This is ugly. Maybe use `Maid.start(%w(version --long))` instead.
|
95
103
|
|
96
104
|
# We can't simply stub `long?` because `options` is a frozen object.
|
97
|
-
options = double('options',
|
105
|
+
options = double('options', long?: true)
|
98
106
|
@app.options = options
|
99
107
|
end
|
100
108
|
|
101
109
|
it 'prints out the gem version' do
|
102
110
|
ua = 'Maid/0.0.1'
|
103
|
-
UserAgent.
|
111
|
+
allow(UserAgent).to receive(:value).and_return(ua)
|
104
112
|
expect(@app).to receive(:say).with(ua)
|
105
113
|
@app.version
|
106
114
|
end
|
@@ -129,10 +137,10 @@ module Maid
|
|
129
137
|
describe App, '#logs' do
|
130
138
|
before do
|
131
139
|
@maid = double('Maid')
|
132
|
-
@maid.
|
133
|
-
@maid.
|
134
|
-
@maid.
|
135
|
-
Maid.
|
140
|
+
allow(@maid).to receive(:clean)
|
141
|
+
allow(@maid).to receive(:log_device).and_return('/var/log/maid.log')
|
142
|
+
allow(@maid).to receive(:load_rules)
|
143
|
+
allow(Maid).to receive(:new).and_return(@maid)
|
136
144
|
end
|
137
145
|
|
138
146
|
describe 'prints out the log' do
|
@@ -142,11 +150,11 @@ module Maid
|
|
142
150
|
@log_file.write(@log)
|
143
151
|
@log_file.close
|
144
152
|
|
145
|
-
@maid.
|
153
|
+
allow(@maid).to receive(:log_device).and_return(@log_file.path)
|
146
154
|
end
|
147
155
|
|
148
156
|
after do
|
149
|
-
@log_file.unlink
|
157
|
+
@log_file.unlink unless @log_file.nil?
|
150
158
|
end
|
151
159
|
|
152
160
|
it 'dumps the last log entries when invoked without an option' do
|
@@ -154,14 +162,14 @@ module Maid
|
|
154
162
|
end
|
155
163
|
|
156
164
|
it 'prints an error when log does not exist' do
|
157
|
-
@maid.
|
165
|
+
allow(@maid).to receive(:log_device).and_return('/maid/file-does-not-exist')
|
158
166
|
message = "Log file #{@maid.log_device} does not exist.\n"
|
159
167
|
|
160
168
|
expect(capture_stderr { App.start(['logs']) }).to eq(message)
|
161
169
|
end
|
162
170
|
|
163
171
|
it 'does not tail when log does not exist' do
|
164
|
-
@maid.
|
172
|
+
allow(@maid).to receive(:log_device).and_return('/maid/file-does-not-exist')
|
165
173
|
message = "Log file #{@maid.log_device} does not exist.\n"
|
166
174
|
|
167
175
|
expect(capture_stderr { App.start(['logs', '--tail']) }).to eq(message)
|
data/spec/lib/maid/maid_spec.rb
CHANGED
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Maid
|
4
4
|
describe Maid do
|
5
|
+
let(:logger) { instance_spy('Logger') }
|
6
|
+
|
5
7
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
FileUtils.stub(:mkdir_p)
|
8
|
+
allow(Logger).to receive(:new).and_return(logger)
|
9
|
+
allow(FileUtils).to receive(:mkdir_p)
|
9
10
|
end
|
10
11
|
|
11
12
|
describe '.new' do
|
@@ -17,45 +18,46 @@ module Maid
|
|
17
18
|
it 'sets up a logger with the given path, when provided' do
|
18
19
|
log_device = '/var/log/maid.log'
|
19
20
|
expect(Logger).to receive(:new).with(log_device, anything, anything)
|
20
|
-
Maid.new(:
|
21
|
+
Maid.new(log_device: log_device)
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'rotates the log with the default settings' do
|
24
|
-
expect(Logger).to receive(:new).with(anything, Maid::DEFAULTS[:log_shift_age],
|
25
|
+
expect(Logger).to receive(:new).with(anything, Maid::DEFAULTS[:log_shift_age],
|
26
|
+
Maid::DEFAULTS[:log_shift_size],)
|
25
27
|
Maid.new
|
26
28
|
end
|
27
29
|
|
28
30
|
it 'rotates the log with the given settings, when provided' do
|
29
31
|
expect(Logger).to receive(:new).with(anything, 42, 1_000_000)
|
30
|
-
Maid.new(:
|
32
|
+
Maid.new(log_shift_age: 42, log_shift_size: 1_000_000)
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'makes the log directory in case it does not exist' do
|
34
36
|
expect(FileUtils).to receive(:mkdir_p).with('/home/username/log')
|
35
|
-
Maid.new(:
|
37
|
+
Maid.new(log_device: '/home/username/log/maid.log')
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'takes a logger object during intialization' do
|
39
|
-
Logger.
|
40
|
-
maid = Maid.new(:
|
41
|
-
expect(maid.logger).to eq(
|
41
|
+
allow(Logger).to receive(:new).and_call_original
|
42
|
+
maid = Maid.new(logger: logger)
|
43
|
+
expect(maid.logger).to eq(logger)
|
42
44
|
end
|
43
45
|
|
44
46
|
describe 'platform-specific behavior' do
|
45
47
|
before do
|
46
|
-
Platform.
|
47
|
-
Platform.
|
48
|
+
allow(Platform).to receive(:linux?)
|
49
|
+
allow(Platform).to receive(:osx?)
|
48
50
|
@home = File.expand_path('~')
|
49
51
|
end
|
50
52
|
|
51
53
|
context 'when running on Linux' do
|
52
54
|
before do
|
53
|
-
Platform.
|
54
|
-
XDG.
|
55
|
+
allow(Platform).to receive(:linux?).and_return(true)
|
56
|
+
allow(XDG).to receive(:[]).with('DATA_HOME').and_return("#{@home}/.local/share")
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'set the trash to the correct default path' do
|
58
|
-
trash_path = "#{
|
60
|
+
trash_path = "#{@home}/.local/share/Trash/files/"
|
59
61
|
expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
|
60
62
|
maid = Maid.new
|
61
63
|
expect(maid.trash_path).to eq(trash_path)
|
@@ -64,11 +66,11 @@ module Maid
|
|
64
66
|
|
65
67
|
context 'when running on OS X' do
|
66
68
|
before do
|
67
|
-
Platform.
|
69
|
+
allow(Platform).to receive(:osx?).and_return(true)
|
68
70
|
end
|
69
71
|
|
70
72
|
it 'sets the trash to the correct default path' do
|
71
|
-
trash_path = "#{
|
73
|
+
trash_path = "#{@home}/.Trash/"
|
72
74
|
expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
|
73
75
|
maid = Maid.new
|
74
76
|
expect(maid.trash_path).to eq(trash_path)
|
@@ -77,7 +79,7 @@ module Maid
|
|
77
79
|
|
78
80
|
context 'when running on an unsupported platform' do
|
79
81
|
it 'does not implement trashing files' do
|
80
|
-
expect
|
82
|
+
expect { Maid.new }.to raise_error(NotImplementedError)
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
@@ -85,19 +87,21 @@ module Maid
|
|
85
87
|
it 'sets the trash to the given path, if provided' do
|
86
88
|
trash_path = '/home/username/tmp/my_trash/'
|
87
89
|
expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
|
88
|
-
maid = Maid.new(:
|
90
|
+
maid = Maid.new(trash_path: trash_path)
|
89
91
|
expect(maid.trash_path).not_to be_nil
|
90
92
|
expect(maid.trash_path).to eq(trash_path)
|
91
93
|
end
|
92
94
|
|
93
95
|
it 'sets the progname for the logger' do
|
94
|
-
expect(@logger).to receive(:progname=).with(Maid::DEFAULTS[:progname])
|
95
96
|
Maid.new
|
97
|
+
|
98
|
+
expect(logger).to have_received(:progname=).with(Maid::DEFAULTS[:progname])
|
96
99
|
end
|
97
100
|
|
98
101
|
it 'sets the progname for the logger to the given name, if provided' do
|
99
|
-
|
100
|
-
|
102
|
+
Maid.new(progname: 'Fran')
|
103
|
+
|
104
|
+
expect(logger).to have_received(:progname=).with('Fran')
|
101
105
|
end
|
102
106
|
|
103
107
|
it 'sets the file options to the defaults' do
|
@@ -105,8 +109,8 @@ module Maid
|
|
105
109
|
end
|
106
110
|
|
107
111
|
it 'sets the file options to the given options, if provided' do
|
108
|
-
maid = Maid.new(:
|
109
|
-
expect(maid.file_options).to eq(:
|
112
|
+
maid = Maid.new(file_options: { verbose: true })
|
113
|
+
expect(maid.file_options).to eq(verbose: true)
|
110
114
|
end
|
111
115
|
|
112
116
|
it 'sets the rules path' do
|
@@ -114,12 +118,12 @@ module Maid
|
|
114
118
|
end
|
115
119
|
|
116
120
|
it 'sets the rules pathto the given path, if provided' do
|
117
|
-
maid = Maid.new(:
|
121
|
+
maid = Maid.new(rules_path: 'Maidfile')
|
118
122
|
expect(maid.rules_path).to eq('Maidfile')
|
119
123
|
end
|
120
124
|
|
121
125
|
it 'ignores nil options' do
|
122
|
-
maid = Maid.new(:
|
126
|
+
maid = Maid.new(rules_path: nil)
|
123
127
|
expect(maid.rules_path).to eq(Maid::DEFAULTS[:rules_path])
|
124
128
|
end
|
125
129
|
end
|
@@ -127,13 +131,14 @@ module Maid
|
|
127
131
|
describe '#clean' do
|
128
132
|
before do
|
129
133
|
@maid = Maid.new
|
130
|
-
|
134
|
+
allow(logger).to receive(:info)
|
131
135
|
end
|
132
136
|
|
133
137
|
it 'logs start and finish' do
|
134
|
-
expect(@logger).to receive(:info).with('Started')
|
135
|
-
expect(@logger).to receive(:info).with('Finished')
|
136
138
|
@maid.clean
|
139
|
+
|
140
|
+
expect(logger).to have_received(:info).with('Started')
|
141
|
+
expect(logger).to have_received(:info).with('Finished')
|
137
142
|
end
|
138
143
|
|
139
144
|
it 'follows the given rules' do
|
@@ -143,20 +148,32 @@ module Maid
|
|
143
148
|
end
|
144
149
|
|
145
150
|
describe '#load_rules' do
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
151
|
+
context 'when there is no LoadError' do
|
152
|
+
before do
|
153
|
+
allow(Kernel).to receive(:load)
|
154
|
+
end
|
155
|
+
|
156
|
+
let(:maid) { Maid.new }
|
150
157
|
|
151
|
-
|
152
|
-
|
153
|
-
|
158
|
+
it 'sets the Maid instance' do
|
159
|
+
expect(::Maid).to receive(:with_instance).with(maid)
|
160
|
+
maid.load_rules
|
161
|
+
end
|
154
162
|
end
|
155
163
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
164
|
+
context 'when there is a LoadError' do
|
165
|
+
let(:maid) { Maid.new }
|
166
|
+
|
167
|
+
before do
|
168
|
+
allow(Kernel).to receive(:load).and_raise(LoadError)
|
169
|
+
allow(Logger).to receive(:warn)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'gives an error on STDERR if there is a LoadError' do
|
173
|
+
maid.load_rules
|
174
|
+
|
175
|
+
expect(logger).to have_received(:warn).once
|
176
|
+
end
|
160
177
|
end
|
161
178
|
end
|
162
179
|
|
@@ -179,8 +196,8 @@ module Maid
|
|
179
196
|
|
180
197
|
describe '#watch' do
|
181
198
|
before do
|
182
|
-
Listen.
|
183
|
-
Listen.
|
199
|
+
allow(Listen).to receive(:to)
|
200
|
+
allow(Listen).to receive(:start)
|
184
201
|
@maid = Maid.new
|
185
202
|
end
|
186
203
|
|
@@ -195,8 +212,9 @@ module Maid
|
|
195
212
|
expect(@maid.watches.first.path).to eq(File.expand_path('watch_dir'))
|
196
213
|
end
|
197
214
|
|
198
|
-
|
199
|
-
|
215
|
+
# FIXME: Example is too long, shouldn't need the rubocop::disable
|
216
|
+
it 'accepts a hash of options and passes them to Listen' do # rubocop:disable RSpec/ExampleLength
|
217
|
+
hash = { some: :options }
|
200
218
|
@maid.watch('some_dir', hash) do
|
201
219
|
rule 'test' do
|
202
220
|
end
|
@@ -232,11 +250,12 @@ module Maid
|
|
232
250
|
expect(@maid.repeats.first.timestring).to eq('1s')
|
233
251
|
end
|
234
252
|
|
235
|
-
|
253
|
+
# FIXME: Example is too long, shouldn't need the rubocop::disable
|
254
|
+
it 'accepts a hash of options and passes them to Rufus' do # rubocop:disable RSpec/ExampleLength
|
236
255
|
scheduler = double('scheduler')
|
237
256
|
expect(Rufus::Scheduler).to receive(:singleton).and_return(scheduler)
|
238
257
|
|
239
|
-
hash = { :
|
258
|
+
hash = { some: :options }
|
240
259
|
@maid.repeat('1s', hash) do
|
241
260
|
rule 'test' do
|
242
261
|
end
|
@@ -249,18 +268,21 @@ module Maid
|
|
249
268
|
end
|
250
269
|
|
251
270
|
describe '#follow_rules' do
|
252
|
-
|
271
|
+
# FIXME: Example is too long, shouldn't need the rubocop::disable
|
272
|
+
it 'follows each rule' do # rubocop:disable RSpec/ExampleLength
|
253
273
|
n = 3
|
254
274
|
maid = Maid.new
|
255
|
-
|
275
|
+
|
256
276
|
rules = (1..n).map do |i|
|
257
|
-
d = double("rule ##{
|
277
|
+
d = double("rule ##{i}", description: 'description')
|
258
278
|
expect(d).to receive(:follow)
|
259
279
|
d
|
260
280
|
end
|
261
281
|
maid.instance_eval { @rules = rules }
|
262
282
|
|
263
283
|
maid.follow_rules
|
284
|
+
|
285
|
+
expect(logger).to have_received(:info).exactly(n).times
|
264
286
|
end
|
265
287
|
end
|
266
288
|
|
@@ -270,11 +292,11 @@ module Maid
|
|
270
292
|
end
|
271
293
|
|
272
294
|
it 'reports `not-a-real-command` as not being a supported command' do
|
273
|
-
expect
|
295
|
+
expect { @maid.cmd('not-a-real-command arg1 arg2') }.to raise_error(NotImplementedError)
|
274
296
|
end
|
275
297
|
|
276
|
-
it '
|
277
|
-
expect
|
298
|
+
it 'reports `echo` as a real command' do
|
299
|
+
expect { @maid.cmd('echo .') }.not_to raise_error
|
278
300
|
end
|
279
301
|
end
|
280
302
|
end
|
@@ -18,7 +18,7 @@ describe Maid::NumericExtensions::SizeToKb do
|
|
18
18
|
it 'tells you that 1 gigabyte equals 1024 megabytes' do
|
19
19
|
expect(1.gigabyte).to eq(1024.megabytes)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it 'tells you that 1 terabyte equals 1024 gigabytes' do
|
23
23
|
expect(1.terabyte).to eq(1024.gigabytes)
|
24
24
|
end
|