maid 0.10.0.pre.alpha.1 → 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/.github/workflows/coverage.yml +29 -0
- data/.github/workflows/lint.yml +24 -0
- data/.github/workflows/release.yml +5 -2
- data/.gitignore +1 -0
- data/.release-please-manifest.json +1 -1
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +372 -0
- data/CHANGELOG.md +8 -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 +29 -22
- data/spec/dependency_spec.rb +9 -8
- data/spec/lib/maid/app_spec.rb +15 -7
- data/spec/lib/maid/maid_spec.rb +63 -41
- data/spec/lib/maid/numeric_extensions_spec.rb +1 -1
- data/spec/lib/maid/rake/single_rule_spec.rb +4 -5
- 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 +87 -85
- data/spec/lib/maid/trash_migration_spec.rb +7 -6
- data/spec/lib/maid_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -3
- metadata +161 -58
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,5 +1,4 @@
|
|
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|
|
@@ -14,29 +13,31 @@ Gem::Specification.new do |s|
|
|
14
13
|
s.description = s.summary
|
15
14
|
s.files = Dir['lib/**/*.rb'] + Dir['bin/maid']
|
16
15
|
s.metadata = {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
+
}
|
23
23
|
|
24
24
|
s.rubyforge_project = 'maid'
|
25
25
|
|
26
26
|
s.required_ruby_version = '>= 2.7.0'
|
27
27
|
|
28
28
|
# Strategy: if possible, use ranges (so there are fewer chances of version conflicts)
|
29
|
-
s.add_dependency('escape', '>= 0.0.1', '< 0.1.0') # Used for better Ruby 1.8.7 support, could be replaced with `Shellwords`
|
30
|
-
s.add_dependency('thor', '~> 1.2.1')
|
31
29
|
s.add_dependency('deprecated', '~> 3.0.0')
|
32
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')
|
33
36
|
s.add_dependency('mime-types', '~> 3.0', '< 4.0')
|
34
37
|
s.add_dependency('rubyzip', '~> 2.3.2')
|
35
|
-
s.add_dependency('xdg', '~> 2.2.3') # previous versions had bugs
|
36
|
-
s.add_dependency('listen', '~> 3.8.0')
|
37
38
|
s.add_dependency('rufus-scheduler', '~> 3.8.2')
|
38
|
-
s.add_dependency('
|
39
|
-
s.add_dependency('
|
39
|
+
s.add_dependency('thor', '~> 1.2.1')
|
40
|
+
s.add_dependency('xdg', '~> 2.2.3') # previous versions had bugs
|
40
41
|
|
41
42
|
# TODO: use one of these two gems instead of `mdfind`. **But** They have to work on Linux as well.
|
42
43
|
#
|
@@ -45,28 +46,34 @@ Gem::Specification.new do |s|
|
|
45
46
|
|
46
47
|
# Strategy: specific versions (since they're just for development)
|
47
48
|
s.add_development_dependency('fakefs', '~> 2.4.0')
|
48
|
-
s.add_development_dependency('
|
49
|
-
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')
|
50
55
|
s.add_development_dependency('rake', '~> 13.0.6')
|
51
56
|
s.add_development_dependency('redcarpet', '~> 3.6.0') # Soft dependency of `yard`
|
52
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')
|
53
62
|
s.add_development_dependency('timecop', '~> 0.9.6')
|
54
63
|
s.add_development_dependency('yard', '>= 0.9.11')
|
55
|
-
s.add_development_dependency('pry-byebug')
|
56
64
|
|
57
65
|
# In Vagrant, polling won't cross over the OS boundary if you develop in the host OS but run your tests in the
|
58
66
|
# guest. One way around this is to force polling instead:
|
59
67
|
#
|
60
68
|
# bundle exec guard --force-polling
|
61
69
|
#
|
62
|
-
s.add_development_dependency('rb-inotify', '~> 0.10.1')
|
63
70
|
s.add_development_dependency('rb-fsevent', '~> 0.11.2')
|
71
|
+
s.add_development_dependency('rb-inotify', '~> 0.10.1')
|
64
72
|
|
65
73
|
s.files = `git ls-files -z`.split("\0")
|
66
|
-
s.
|
67
|
-
s.
|
68
|
-
s.require_paths = %w(lib)
|
74
|
+
s.executables = `git ls-files -z -- bin/*`.split("\0").map { |f| File.basename(f) }
|
75
|
+
s.require_paths = %w[lib]
|
69
76
|
|
70
77
|
s.post_install_message = "🙏 Thank you for installing Maid, we hope it's " \
|
71
|
-
|
78
|
+
"useful to you! Visit #{s.homepage} to report issues or contribute code."
|
72
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,7 +29,6 @@ end
|
|
21
29
|
|
22
30
|
module Maid
|
23
31
|
describe App, '#clean' do
|
24
|
-
|
25
32
|
before do
|
26
33
|
@app = App.new
|
27
34
|
allow(@app).to receive(:maid_options)
|
@@ -29,7 +36,8 @@ module Maid
|
|
29
36
|
|
30
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
42
|
allow(@maid).to receive(:clean)
|
35
43
|
allow(@maid).to receive(:log_device)
|
@@ -38,16 +46,16 @@ module Maid
|
|
38
46
|
end
|
39
47
|
|
40
48
|
it 'makes a new Maid with the options' do
|
41
|
-
opts = { :
|
49
|
+
opts = { foo: 'bar' }
|
42
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,7 +102,7 @@ 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
|
|
@@ -146,7 +154,7 @@ module Maid
|
|
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
|
data/spec/lib/maid/maid_spec.rb
CHANGED
@@ -2,9 +2,10 @@ 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
|
-
allow(Logger).to receive(:new).and_return(@logger)
|
8
|
+
allow(Logger).to receive(:new).and_return(logger)
|
8
9
|
allow(FileUtils).to receive(:mkdir_p)
|
9
10
|
end
|
10
11
|
|
@@ -17,28 +18,29 @@ 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
41
|
allow(Logger).to receive(:new).and_call_original
|
40
|
-
maid = Maid.new(:
|
41
|
-
expect(maid.logger).to eq(
|
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
|
@@ -51,11 +53,11 @@ module Maid
|
|
51
53
|
context 'when running on Linux' do
|
52
54
|
before do
|
53
55
|
allow(Platform).to receive(:linux?).and_return(true)
|
54
|
-
allow(XDG).to receive(:[]).with('DATA_HOME').and_return("#{
|
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)
|
@@ -68,7 +70,7 @@ module Maid
|
|
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)
|
@@ -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
|
-
allow(
|
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
|
|
@@ -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
|
|
@@ -273,7 +295,7 @@ module Maid
|
|
273
295
|
expect { @maid.cmd('not-a-real-command arg1 arg2') }.to raise_error(NotImplementedError)
|
274
296
|
end
|
275
297
|
|
276
|
-
it '
|
298
|
+
it 'reports `echo` as a real command' do
|
277
299
|
expect { @maid.cmd('echo .') }.not_to raise_error
|
278
300
|
end
|
279
301
|
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
|
@@ -5,7 +5,7 @@ module Maid
|
|
5
5
|
describe SingleRule, fakefs: true do
|
6
6
|
subject(:single_rule) { described_class.new name, task }
|
7
7
|
let(:name) { double(:rule_description) }
|
8
|
-
let(:task) {
|
8
|
+
let(:task) { proc {} }
|
9
9
|
|
10
10
|
before do
|
11
11
|
logfile = File.join('~', '.maid', 'maid.log')
|
@@ -15,11 +15,11 @@ module Maid
|
|
15
15
|
|
16
16
|
describe '#initialize' do
|
17
17
|
it 'has a name' do
|
18
|
-
expect(single_rule.name).
|
18
|
+
expect(single_rule.name).to eq(name)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'has a task' do
|
22
|
-
expect(single_rule.task).
|
22
|
+
expect(single_rule.task).to eq(task)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -74,7 +74,7 @@ module Maid
|
|
74
74
|
describe '.perform' do
|
75
75
|
subject(:perform) { described_class.perform name, task }
|
76
76
|
let(:name) { double(:name) }
|
77
|
-
let(:task) {
|
77
|
+
let(:task) { proc {} }
|
78
78
|
|
79
79
|
it 'creates an instance' do
|
80
80
|
expect(described_class)
|
@@ -98,7 +98,6 @@ module Maid
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
@@ -3,11 +3,10 @@ require 'spec_helper'
|
|
3
3
|
module Maid
|
4
4
|
module Rake
|
5
5
|
describe Task do
|
6
|
-
|
7
6
|
before(:all) { ::Rake::TaskManager.record_task_metadata = true }
|
8
7
|
|
9
|
-
subject(:define_task) { described_class.new
|
10
|
-
let(:instructions) {
|
8
|
+
subject(:define_task) { described_class.new(*args, &instructions) }
|
9
|
+
let(:instructions) { proc {} }
|
11
10
|
|
12
11
|
describe '#initialize' do
|
13
12
|
before { ::Rake::Task.clear }
|
@@ -36,7 +35,7 @@ module Maid
|
|
36
35
|
end
|
37
36
|
|
38
37
|
context 'given a description argument' do
|
39
|
-
let(:args) { [:foobar, description: 'Custom description'] }
|
38
|
+
let(:args) { [:foobar, { description: 'Custom description' }] }
|
40
39
|
|
41
40
|
it 'defines a rake task with the description provided' do
|
42
41
|
define_task
|
@@ -45,7 +44,6 @@ module Maid
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|