maid 0.5.0 → 0.6.0.alpha.1

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.
@@ -9,36 +9,36 @@ module Maid
9
9
  end
10
10
 
11
11
  describe '.new' do
12
- it 'should set up a logger with the default path' do
13
- Logger.should_receive(:new).with(Maid::DEFAULTS[:log_device], anything, anything)
12
+ it 'sets up a logger with the default path' do
13
+ expect(Logger).to receive(:new).with(Maid::DEFAULTS[:log_device], anything, anything)
14
14
  Maid.new
15
15
  end
16
16
 
17
- it 'should set up a logger with the given path, when provided' do
17
+ it 'sets up a logger with the given path, when provided' do
18
18
  log_device = '/var/log/maid.log'
19
- Logger.should_receive(:new).with(log_device, anything, anything)
19
+ expect(Logger).to receive(:new).with(log_device, anything, anything)
20
20
  Maid.new(:log_device => log_device)
21
21
  end
22
22
 
23
- it 'should rotate the log with the default settings' do
24
- Logger.should_receive(:new).with(anything, Maid::DEFAULTS[:log_shift_age], Maid::DEFAULTS[:log_shift_size])
23
+ it 'rotates the log with the default settings' do
24
+ expect(Logger).to receive(:new).with(anything, Maid::DEFAULTS[:log_shift_age], Maid::DEFAULTS[:log_shift_size])
25
25
  Maid.new
26
26
  end
27
27
 
28
- it 'should rotate the log with the given settings, when provided' do
29
- Logger.should_receive(:new).with(anything, 42, 1_000_000)
28
+ it 'rotates the log with the given settings, when provided' do
29
+ expect(Logger).to receive(:new).with(anything, 42, 1_000_000)
30
30
  Maid.new(:log_shift_age => 42, :log_shift_size => 1_000_000)
31
31
  end
32
32
 
33
- it 'should make the log directory in case it does not exist' do
34
- FileUtils.should_receive(:mkdir_p).with('/home/username/log')
33
+ it 'makes the log directory in case it does not exist' do
34
+ expect(FileUtils).to receive(:mkdir_p).with('/home/username/log')
35
35
  Maid.new(:log_device => '/home/username/log/maid.log')
36
36
  end
37
37
 
38
- it 'should take a logger object during intialization' do
38
+ it 'takes a logger object during intialization' do
39
39
  Logger.unstub(:new)
40
40
  maid = Maid.new(:logger => @logger)
41
- maid.logger.should == @logger
41
+ expect(maid.logger).to eq(@logger)
42
42
  end
43
43
 
44
44
  describe 'platform-specific behavior' do
@@ -54,11 +54,11 @@ module Maid
54
54
  XDG.stub(:[]).with('DATA_HOME') { "#{ @home }/.local/share" }
55
55
  end
56
56
 
57
- it 'should set the trash to the correct default path' do
57
+ it 'set the trash to the correct default path' do
58
58
  trash_path = "#{ @home }/.local/share/Trash/files/"
59
- FileUtils.should_receive(:mkdir_p).with(trash_path).once
59
+ expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
60
60
  maid = Maid.new
61
- maid.trash_path.should == trash_path
61
+ expect(maid.trash_path).to eq(trash_path)
62
62
  end
63
63
  end
64
64
 
@@ -67,60 +67,60 @@ module Maid
67
67
  Platform.stub(:osx?) { true }
68
68
  end
69
69
 
70
- it 'should set the trash to the correct default path' do
70
+ it 'sets the trash to the correct default path' do
71
71
  trash_path = "#{ @home }/.Trash/"
72
- FileUtils.should_receive(:mkdir_p).with(trash_path).once
72
+ expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
73
73
  maid = Maid.new
74
- maid.trash_path.should == trash_path
74
+ expect(maid.trash_path).to eq(trash_path)
75
75
  end
76
76
  end
77
77
 
78
78
  context 'when running on an unsupported platform' do
79
79
  it 'does not implement trashing files' do
80
- lambda { Maid.new }.should raise_error(NotImplementedError)
80
+ expect(lambda { Maid.new }).to raise_error(NotImplementedError)
81
81
  end
82
82
  end
83
83
  end
84
84
 
85
- it 'should set the trash to the given path, if provided' do
85
+ it 'sets the trash to the given path, if provided' do
86
86
  trash_path = '/home/username/tmp/my_trash/'
87
- FileUtils.should_receive(:mkdir_p).with(trash_path).once
87
+ expect(FileUtils).to receive(:mkdir_p).with(trash_path).once
88
88
  maid = Maid.new(:trash_path => trash_path)
89
- maid.trash_path.should_not be_nil
90
- maid.trash_path.should == trash_path
89
+ expect(maid.trash_path).not_to be_nil
90
+ expect(maid.trash_path).to eq(trash_path)
91
91
  end
92
92
 
93
- it 'should set the progname for the logger' do
94
- @logger.should_receive(:progname=).with(Maid::DEFAULTS[:progname])
93
+ it 'sets the progname for the logger' do
94
+ expect(@logger).to receive(:progname=).with(Maid::DEFAULTS[:progname])
95
95
  Maid.new
96
96
  end
97
97
 
98
- it 'should set the progname for the logger to the given name, if provided' do
99
- @logger.should_receive(:progname=).with('Fran')
98
+ it 'sets the progname for the logger to the given name, if provided' do
99
+ expect(@logger).to receive(:progname=).with('Fran')
100
100
  Maid.new(:progname => 'Fran')
101
101
  end
102
102
 
103
- it 'should set the file options to the defaults' do
104
- Maid.new.file_options.should == Maid::DEFAULTS[:file_options]
103
+ it 'sets the file options to the defaults' do
104
+ expect(Maid.new.file_options).to eq(Maid::DEFAULTS[:file_options])
105
105
  end
106
106
 
107
- it 'should set the file options to the given options, if provided' do
107
+ it 'sets the file options to the given options, if provided' do
108
108
  maid = Maid.new(:file_options => { :verbose => true })
109
- maid.file_options.should == { :verbose => true }
109
+ expect(maid.file_options).to eq(:verbose => true)
110
110
  end
111
111
 
112
- it 'should set the rules path' do
113
- Maid.new.rules_path.should == Maid::DEFAULTS[:rules_path]
112
+ it 'sets the rules path' do
113
+ expect(Maid.new.rules_path).to eq(Maid::DEFAULTS[:rules_path])
114
114
  end
115
115
 
116
- it 'should set the ruels pathto the given path, if provided' do
116
+ it 'sets the rules pathto the given path, if provided' do
117
117
  maid = Maid.new(:rules_path => 'Maidfile')
118
- maid.rules_path.should == 'Maidfile'
118
+ expect(maid.rules_path).to eq('Maidfile')
119
119
  end
120
120
 
121
- it 'should ignore nil options' do
121
+ it 'ignores nil options' do
122
122
  maid = Maid.new(:rules_path => nil)
123
- maid.rules_path.should == Maid::DEFAULTS[:rules_path]
123
+ expect(maid.rules_path).to eq(Maid::DEFAULTS[:rules_path])
124
124
  end
125
125
  end
126
126
 
@@ -130,14 +130,14 @@ module Maid
130
130
  @logger.stub(:info)
131
131
  end
132
132
 
133
- it 'should log start and finish' do
134
- @logger.should_receive(:info).with('Started')
135
- @logger.should_receive(:info).with('Finished')
133
+ it 'logs start and finish' do
134
+ expect(@logger).to receive(:info).with('Started')
135
+ expect(@logger).to receive(:info).with('Finished')
136
136
  @maid.clean
137
137
  end
138
138
 
139
- it 'should follow the given rules' do
140
- @maid.should_receive(:follow_rules)
139
+ it 'follows the given rules' do
140
+ expect(@maid).to receive(:follow_rules)
141
141
  @maid.clean
142
142
  end
143
143
  end
@@ -148,14 +148,14 @@ module Maid
148
148
  @maid = Maid.new
149
149
  end
150
150
 
151
- it 'should set the Maid instance' do
152
- ::Maid.should_receive(:with_instance).with(@maid)
151
+ it 'sets the Maid instance' do
152
+ expect(::Maid).to receive(:with_instance).with(@maid)
153
153
  @maid.load_rules
154
154
  end
155
155
 
156
- it 'should give an error on STDERR if there is a LoadError' do
156
+ it 'gives an error on STDERR if there is a LoadError' do
157
157
  Kernel.stub(:load).and_raise(LoadError)
158
- STDERR.should_receive(:puts)
158
+ expect(STDERR).to receive(:puts)
159
159
  @maid.load_rules
160
160
  end
161
161
  end
@@ -165,26 +165,26 @@ module Maid
165
165
  @maid = Maid.new
166
166
  end
167
167
 
168
- it 'should add a rule to the list of rules' do
169
- @maid.rules.length.should == 0
168
+ it 'adds a rule to the list of rules' do
169
+ expect(@maid.rules.length).to eq(0)
170
170
 
171
171
  @maid.rule('description') do
172
172
  'instructions'
173
173
  end
174
174
 
175
- @maid.rules.length.should == 1
176
- @maid.rules.first.description.should == 'description'
175
+ expect(@maid.rules.length).to eq(1)
176
+ expect(@maid.rules.first.description).to eq('description')
177
177
  end
178
178
  end
179
179
 
180
180
  describe '#follow_rules' do
181
- it 'should follow each rule' do
181
+ it 'follows each rule' do
182
182
  n = 3
183
183
  maid = Maid.new
184
- @logger.should_receive(:info).exactly(n).times
184
+ expect(@logger).to receive(:info).exactly(n).times
185
185
  rules = (1..n).map do |n|
186
186
  d = double("rule ##{ n }", :description => 'description')
187
- d.should_receive(:follow)
187
+ expect(d).to receive(:follow)
188
188
  d
189
189
  end
190
190
  maid.instance_eval { @rules = rules }
@@ -198,12 +198,12 @@ module Maid
198
198
  @maid = Maid.new
199
199
  end
200
200
 
201
- it 'should report `not-a-real-command` as not being a supported command' do
202
- lambda { @maid.cmd('not-a-real-command arg1 arg2') }.should raise_error(NotImplementedError)
201
+ it 'reports `not-a-real-command` as not being a supported command' do
202
+ expect(lambda { @maid.cmd('not-a-real-command arg1 arg2') }).to raise_error(NotImplementedError)
203
203
  end
204
204
 
205
205
  it 'should report `echo` as a real command' do
206
- lambda { @maid.cmd('echo .') }.should_not raise_error
206
+ expect(lambda { @maid.cmd('echo .') }).not_to raise_error
207
207
  end
208
208
  end
209
209
  end
@@ -1,25 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Maid::NumericExtensions::Time, '#since?' do
4
- it 'should tell you that 1 week ago happened after 2 weeks ago' do
5
- 1.week.since?(2.weeks.ago).should be_true
4
+ it 'tells you that 1 week ago happened after 2 weeks ago' do
5
+ expect(1.week.since?(2.weeks.ago)).to be(true)
6
6
  end
7
7
 
8
- it 'should tell you that 2 weeks ago was not after 1 week ago' do
9
- 2.week.since?(1.weeks.ago).should be_false
8
+ it 'tells you that 2 weeks ago was not after 1 week ago' do
9
+ expect(2.week.since?(1.weeks.ago)).to be(false)
10
10
  end
11
11
  end
12
12
 
13
13
  describe Maid::NumericExtensions::SizeToKb do
14
- it 'should tell you that 1 megabyte equals 1024 kilobytes' do
15
- 1.megabyte.should == 1024.kilobytes
14
+ it 'tells you that 1 megabyte equals 1024 kilobytes' do
15
+ expect(1.megabyte).to eq(1024.kilobytes)
16
16
  end
17
17
 
18
- it 'should tell you that 1 gigabyte equals 1024 megabytes' do
19
- 1.gigabyte.should == 1024.megabytes
18
+ it 'tells you that 1 gigabyte equals 1024 megabytes' do
19
+ expect(1.gigabyte).to eq(1024.megabytes)
20
20
  end
21
21
 
22
- it 'should tell you that 1 terabyte equals 1024 gigabytes' do
23
- 1.terabyte.should == 1024.gigabytes
22
+ it 'tells you that 1 terabyte equals 1024 gigabytes' do
23
+ expect(1.terabyte).to eq(1024.gigabytes)
24
24
  end
25
25
  end
@@ -9,7 +9,7 @@ module Maid
9
9
  describe 'determining the host OS' do
10
10
  it 'delegates to RbConfig' do
11
11
  stub_host_os('foo')
12
- subject.host_os.should == 'foo'
12
+ expect(subject.host_os).to eq('foo')
13
13
  end
14
14
  end
15
15
 
@@ -19,15 +19,15 @@ module Maid
19
19
  end
20
20
 
21
21
  it 'is identified as Linux' do
22
- subject.linux?.should be_true
22
+ expect(subject.linux?).to be(true)
23
23
  end
24
24
 
25
25
  it 'is not identified as OS X' do
26
- subject.osx?.should be_false
26
+ expect(subject.osx?).to be(false)
27
27
  end
28
28
 
29
29
  it 'locate is "locate"' do
30
- Platform::Commands.locate.should match(/locate/)
30
+ expect(Platform::Commands.locate).to match(/locate/)
31
31
  end
32
32
  end
33
33
 
@@ -37,15 +37,15 @@ module Maid
37
37
  end
38
38
 
39
39
  it 'is not identified as Linux' do
40
- subject.linux?.should be_false
40
+ expect(subject.linux?).to be(false)
41
41
  end
42
42
 
43
43
  it 'is identified as OS X' do
44
- subject.osx?.should be_true
44
+ expect(subject.osx?).to be(true)
45
45
  end
46
46
 
47
47
  it 'locate is "mdfind"' do
48
- Platform::Commands.locate.should match(/mdfind/)
48
+ expect(Platform::Commands.locate).to match(/mdfind/)
49
49
  end
50
50
  end
51
51
  end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ module Maid
4
+ module Rake
5
+ describe SingleRule do
6
+ subject(:single_rule) { described_class.new name, task }
7
+ let(:name) { double(:rule_description) }
8
+ let(:task) { Proc.new {} }
9
+
10
+ describe '#initialize' do
11
+ its(:name) { should eq(name) }
12
+ its(:task) { should eq(task) }
13
+ end
14
+
15
+ describe '#clean' do
16
+ let(:maid) { double(:maid_instance) }
17
+
18
+ before do
19
+ single_rule.maid_instance = maid
20
+ end
21
+
22
+ it 'calls #clean on maid_instance' do
23
+ expect(maid).to receive(:clean)
24
+ single_rule.clean
25
+ end
26
+ end
27
+
28
+ describe '#maid_instance' do
29
+ let(:maid_instance) { single_rule.maid_instance }
30
+
31
+ it 'instantiates a Maid with the proper arguments' do
32
+ expect(Maid).to receive(:new).with(rules_path: '/dev/null')
33
+ maid_instance
34
+ end
35
+
36
+ it 'returns a Maid instance' do
37
+ expect(maid_instance).to be_a(Maid)
38
+ end
39
+
40
+ it 'memoizes the result' do
41
+ expect(Maid).to receive(:new).once
42
+ maid_instance
43
+ maid_instance
44
+ end
45
+ end
46
+
47
+ describe '#define' do
48
+ let(:maid) { double(:maid_instance) }
49
+
50
+ before { single_rule.maid_instance = maid }
51
+
52
+ it 'defines a single rule upon maid instance' do
53
+ expect(maid).to receive(:rule).with(name, &task)
54
+ single_rule.define
55
+ end
56
+
57
+ it 'returns self' do
58
+ allow(maid).to receive(:rule).with(name, &task)
59
+ expect(single_rule.define).to eq(single_rule)
60
+ end
61
+ end
62
+
63
+ describe '.perform' do
64
+ subject(:perform) { described_class.perform name, task }
65
+ let(:name) { double(:name) }
66
+ let(:task) { Proc.new {} }
67
+
68
+ it 'creates an instance' do
69
+ expect(described_class)
70
+ .to receive(:new)
71
+ .with(name, task)
72
+ .and_call_original
73
+ perform
74
+ end
75
+
76
+ describe 'instance methods calling' do
77
+ let(:instance) { double(:single_rule).as_null_object }
78
+
79
+ before do
80
+ allow(described_class).to receive(:new).and_return(instance)
81
+ end
82
+
83
+ it 'calls #define and #clean on instance' do
84
+ expect(instance).to receive(:define)
85
+ expect(instance).to receive(:clean)
86
+ perform
87
+ end
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Maid
4
+ module Rake
5
+ describe Task do
6
+
7
+ before(:all) { ::Rake::TaskManager.record_task_metadata = true }
8
+
9
+ subject(:define_task) { described_class.new *args, &instructions }
10
+ let(:instructions) { Proc.new {} }
11
+
12
+ describe '#initialize' do
13
+ before { ::Rake::Task.clear }
14
+
15
+ describe 'task body' do
16
+ let(:args) { :foobar }
17
+
18
+ it 'sends given instructions to SingleRule' do
19
+ expect(SingleRule)
20
+ .to receive(:perform)
21
+ .with('foobar', instructions)
22
+ define_task && ::Rake::Task[:foobar].execute
23
+ end
24
+ end
25
+
26
+ describe 'task description' do
27
+ context 'given just the task name as argument' do
28
+ let(:args) { [:foobar] }
29
+
30
+ it 'defines a rake task with default description' do
31
+ desc = described_class.const_get 'DEFAULT_DESCRIPTION'
32
+
33
+ define_task
34
+ expect(::Rake::Task[:foobar].comment).to eq(desc)
35
+ end
36
+ end
37
+
38
+ context 'given a description argument' do
39
+ let(:args) { [:foobar, description: 'Custom description'] }
40
+
41
+ it 'defines a rake task with the description provided' do
42
+ define_task
43
+ expect(::Rake::Task[:foobar].comment).to eq('Custom description')
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module Maid
4
4
  describe Rule do
5
- it 'should be able to be followed' do
5
+ it 'is able to be followed' do
6
6
  rule = Rule.new('my rule', lambda { 1 + 2 })
7
- rule.follow.should == 3
7
+ expect(rule.follow).to eq(3)
8
8
  end
9
9
  end
10
10
  end