listen 2.7.4 → 2.7.5
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/.rubocop.yml +232 -0
- data/.travis.yml +6 -3
- data/Gemfile +9 -1
- data/Guardfile +6 -1
- data/README.md +17 -4
- data/lib/listen.rb +9 -4
- data/lib/listen/adapter.rb +5 -7
- data/lib/listen/adapter/base.rb +8 -5
- data/lib/listen/adapter/bsd.rb +58 -21
- data/lib/listen/adapter/darwin.rb +2 -4
- data/lib/listen/adapter/linux.rb +20 -10
- data/lib/listen/adapter/polling.rb +0 -2
- data/lib/listen/adapter/tcp.rb +6 -5
- data/lib/listen/adapter/windows.rb +8 -6
- data/lib/listen/change.rb +1 -2
- data/lib/listen/cli.rb +25 -22
- data/lib/listen/directory.rb +8 -6
- data/lib/listen/listener.rb +25 -19
- data/lib/listen/record.rb +4 -2
- data/lib/listen/silencer.rb +55 -25
- data/lib/listen/tcp.rb +9 -0
- data/lib/listen/tcp/broadcaster.rb +0 -2
- data/lib/listen/tcp/listener.rb +13 -8
- data/lib/listen/tcp/message.rb +0 -2
- data/lib/listen/version.rb +1 -1
- data/listen.gemspec +4 -3
- data/spec/acceptance/listen_spec.rb +190 -109
- data/spec/acceptance/tcp_spec.rb +28 -26
- data/spec/lib/listen/adapter/base_spec.rb +14 -12
- data/spec/lib/listen/adapter/bsd_spec.rb +5 -2
- data/spec/lib/listen/adapter/darwin_spec.rb +5 -2
- data/spec/lib/listen/adapter/linux_spec.rb +40 -25
- data/spec/lib/listen/adapter/polling_spec.rb +29 -14
- data/spec/lib/listen/adapter/tcp_spec.rb +24 -6
- data/spec/lib/listen/adapter/windows_spec.rb +5 -2
- data/spec/lib/listen/adapter_spec.rb +20 -17
- data/spec/lib/listen/change_spec.rb +36 -26
- data/spec/lib/listen/directory_spec.rb +128 -71
- data/spec/lib/listen/file_spec.rb +67 -34
- data/spec/lib/listen/listener_spec.rb +135 -105
- data/spec/lib/listen/record_spec.rb +32 -29
- data/spec/lib/listen/silencer_spec.rb +78 -56
- data/spec/lib/listen/tcp/broadcaster_spec.rb +3 -2
- data/spec/lib/listen/tcp/listener_spec.rb +17 -11
- data/spec/lib/listen/tcp/message_spec.rb +1 -1
- data/spec/lib/listen_spec.rb +18 -6
- data/spec/spec_helper.rb +5 -1
- data/spec/support/acceptance_helper.rb +3 -3
- data/spec/support/fixtures_helper.rb +10 -9
- metadata +17 -15
@@ -3,83 +3,111 @@ require 'spec_helper'
|
|
3
3
|
describe Listen::File do
|
4
4
|
let(:registry) { double(Celluloid::Registry) }
|
5
5
|
let(:listener) { double(Listen::Listener, registry: registry, options: {}) }
|
6
|
-
|
6
|
+
|
7
|
+
let(:record) do
|
8
|
+
double(Listen::Record, async: double(set_path: true, unset_path: true))
|
9
|
+
end
|
10
|
+
|
7
11
|
let(:path) { Pathname.new(Dir.pwd) }
|
8
|
-
around { |example| fixtures {
|
12
|
+
around { |example| fixtures { example.run } }
|
9
13
|
before { registry.stub(:[]).with(:record) { record } }
|
10
14
|
|
11
|
-
describe
|
15
|
+
describe '#change' do
|
12
16
|
let(:file_path) { path.join('file.rb') }
|
13
17
|
let(:file) { Listen::File.new(listener, file_path) }
|
14
|
-
let(:expected_data) { { type: 'File', mtime: kind_of(Float), mode: kind_of(Integer) } }
|
15
18
|
|
16
|
-
|
19
|
+
let(:expected_data) do
|
20
|
+
{ type: 'File', mtime: kind_of(Float), mode: kind_of(Integer) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'path present in record' do
|
17
24
|
let(:record_mtime) { nil }
|
18
25
|
let(:record_md5) { nil }
|
19
26
|
let(:record_mode) { nil }
|
20
|
-
let(:record_data) { { type: 'File', mtime: record_mtime, md5: record_md5, mode: record_mode } }
|
21
|
-
before { record.stub_chain(:future, :file_data) { double(value: record_data) } }
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
let(:record_data) do
|
29
|
+
{ type: 'File',
|
30
|
+
mtime: record_mtime,
|
31
|
+
md5: record_md5,
|
32
|
+
mode: record_mode }
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
record.stub_chain(:future, :file_data) { double(value: record_data) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'non-existing path' do
|
40
|
+
it 'returns added' do
|
25
41
|
expect(file.change).to eq :removed
|
26
42
|
end
|
27
|
-
it
|
43
|
+
it 'sets path in record' do
|
28
44
|
expect(record.async).to receive(:unset_path).with(file_path)
|
29
45
|
file.change
|
30
46
|
end
|
31
47
|
end
|
32
48
|
|
33
|
-
context
|
34
|
-
around
|
49
|
+
context 'existing path' do
|
50
|
+
around do |example|
|
51
|
+
touch file_path
|
52
|
+
example.run
|
53
|
+
end
|
35
54
|
|
36
|
-
context
|
55
|
+
context 'old record path mtime' do
|
37
56
|
let(:record_mtime) { (Time.now - 1).to_f }
|
38
57
|
|
39
|
-
it
|
58
|
+
it 'returns modified' do
|
40
59
|
expect(file.change).to eq :modified
|
41
60
|
end
|
42
61
|
|
43
|
-
it
|
44
|
-
expect(record.async).to receive(:set_path).
|
62
|
+
it 'sets path in record with expected data' do
|
63
|
+
expect(record.async).to receive(:set_path).
|
64
|
+
with(file_path, expected_data)
|
65
|
+
|
45
66
|
file.change
|
46
67
|
end
|
47
68
|
end
|
48
69
|
|
49
|
-
context
|
70
|
+
context 'same record path mtime' do
|
50
71
|
let(:record_mtime) { ::File.lstat(file_path).mtime.to_f }
|
51
72
|
let(:record_mode) { ::File.lstat(file_path).mode }
|
52
73
|
|
53
|
-
context
|
54
|
-
it
|
74
|
+
context 'same record path mode' do
|
75
|
+
it 'returns nil' do
|
55
76
|
expect(file.change).to be_nil
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
59
|
-
context
|
80
|
+
context 'diferent record path mode' do
|
60
81
|
let(:record_mode) { 'foo' }
|
61
82
|
|
62
|
-
it
|
83
|
+
it 'returns modified' do
|
63
84
|
expect(file.change).to eq :modified
|
64
85
|
end
|
65
86
|
end
|
66
87
|
|
67
|
-
context
|
68
|
-
it
|
88
|
+
context 'same record path md5' do
|
89
|
+
it 'returns nil' do
|
69
90
|
expect(file.change).to be_nil
|
70
91
|
end
|
71
92
|
end
|
72
93
|
|
73
94
|
if darwin?
|
74
|
-
context
|
95
|
+
context 'different record path md5' do
|
75
96
|
let(:record_md5) { 'foo' }
|
76
|
-
let(:expected_data)
|
97
|
+
let(:expected_data) do
|
98
|
+
{ type: 'File',
|
99
|
+
mtime: kind_of(Float),
|
100
|
+
mode: kind_of(Integer),
|
101
|
+
md5: kind_of(String) }
|
102
|
+
end
|
77
103
|
|
78
|
-
it
|
104
|
+
it 'returns modified' do
|
79
105
|
expect(file.change).to eq :modified
|
80
106
|
end
|
81
|
-
it
|
82
|
-
expect(record.async).to receive(:set_path).
|
107
|
+
it 'sets path in record with expected data' do
|
108
|
+
expect(record.async).to receive(:set_path).
|
109
|
+
with(file_path, expected_data)
|
110
|
+
|
83
111
|
file.change
|
84
112
|
end
|
85
113
|
end
|
@@ -89,18 +117,23 @@ describe Listen::File do
|
|
89
117
|
end
|
90
118
|
end
|
91
119
|
|
92
|
-
context
|
120
|
+
context 'path not present in record' do
|
93
121
|
before { record.stub_chain(:future, :file_data) { double(value: {}) } }
|
94
122
|
|
95
|
-
context
|
96
|
-
around
|
123
|
+
context 'existing path' do
|
124
|
+
around do |example|
|
125
|
+
touch file_path
|
126
|
+
example.run
|
127
|
+
end
|
97
128
|
|
98
|
-
it
|
129
|
+
it 'returns added' do
|
99
130
|
expect(file.change).to eq :added
|
100
131
|
end
|
101
132
|
|
102
|
-
it
|
103
|
-
expect(record.async).to receive(:set_path).
|
133
|
+
it 'sets path in record with expected data' do
|
134
|
+
expect(record.async).to receive(:set_path).
|
135
|
+
with(file_path, expected_data)
|
136
|
+
|
104
137
|
file.change
|
105
138
|
end
|
106
139
|
end
|
@@ -4,13 +4,20 @@ describe Listen::Listener do
|
|
4
4
|
let(:listener) { Listen::Listener.new(options) }
|
5
5
|
let(:options) { {} }
|
6
6
|
let(:registry) { double(Celluloid::Registry, :[]= => true) }
|
7
|
-
|
7
|
+
|
8
|
+
let(:supervisor) do
|
9
|
+
double(Celluloid::SupervisionGroup,
|
10
|
+
add: true,
|
11
|
+
pool: true)
|
12
|
+
end
|
13
|
+
|
8
14
|
let(:record) { double(Listen::Record, terminate: true, build: true) }
|
9
15
|
let(:silencer) { double(Listen::Silencer, terminate: true) }
|
10
|
-
let(:
|
16
|
+
let(:adapter_class) { double(:adapter_class, local_fs?: true) }
|
17
|
+
let(:adapter) { double(Listen::Adapter::Base, class: adapter_class) }
|
11
18
|
let(:change_pool) { double(Listen::Change, terminate: true) }
|
12
19
|
let(:change_pool_async) { double('ChangePoolAsync') }
|
13
|
-
before
|
20
|
+
before do
|
14
21
|
Celluloid::Registry.stub(:new) { registry }
|
15
22
|
Celluloid::SupervisionGroup.stub(:run!) { supervisor }
|
16
23
|
registry.stub(:[]).with(:silencer) { silencer }
|
@@ -18,98 +25,110 @@ describe Listen::Listener do
|
|
18
25
|
registry.stub(:[]).with(:record) { record }
|
19
26
|
registry.stub(:[]).with(:change_pool) { change_pool }
|
20
27
|
|
21
|
-
|
28
|
+
end
|
22
29
|
|
23
|
-
describe
|
24
|
-
it
|
30
|
+
describe 'initialize' do
|
31
|
+
it 'sets paused to false' do
|
25
32
|
expect(listener).not_to be_paused
|
26
33
|
end
|
27
34
|
|
28
|
-
it
|
29
|
-
block =
|
35
|
+
it 'sets block' do
|
36
|
+
block = proc {}
|
30
37
|
listener = Listen::Listener.new('lib', &block)
|
31
38
|
expect(listener.block).not_to be_nil
|
32
39
|
end
|
33
40
|
|
34
|
-
it
|
41
|
+
it 'sets directories with realpath' do
|
35
42
|
listener = Listen::Listener.new('lib', 'spec')
|
36
|
-
|
43
|
+
expected = %w(lib spec).map { |dir| Pathname.pwd.join(dir) }
|
44
|
+
expect(listener.directories).to eq expected
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
expect(listener.options).to eq(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
it
|
51
|
-
listener = Listen::Listener.new('lib',
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
describe 'options' do
|
49
|
+
it 'sets default options' do
|
50
|
+
expect(listener.options).to eq(
|
51
|
+
debug: false,
|
52
|
+
latency: nil,
|
53
|
+
wait_for_delay: 0.1,
|
54
|
+
force_polling: false,
|
55
|
+
polling_fallback_message: nil)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets new options on initialize' do
|
59
|
+
listener = Listen::Listener.new('lib',
|
60
|
+
latency: 1.234,
|
61
|
+
wait_for_delay: 0.85)
|
62
|
+
|
63
|
+
expect(listener.options).to eq(
|
64
|
+
debug: false,
|
65
|
+
latency: 1.234,
|
66
|
+
wait_for_delay: 0.85,
|
67
|
+
force_polling: false,
|
68
|
+
polling_fallback_message: nil)
|
58
69
|
end
|
59
70
|
end
|
60
71
|
|
61
|
-
describe
|
62
|
-
before
|
72
|
+
describe '#start' do
|
73
|
+
before do
|
63
74
|
adapter.stub_chain(:async, :start)
|
64
75
|
silencer.stub(:silenced?) { false }
|
65
|
-
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'registers silencer' do
|
79
|
+
expect(supervisor).to receive(:add).
|
80
|
+
with(Listen::Silencer, as: :silencer, args: listener)
|
66
81
|
|
67
|
-
it "registers silencer" do
|
68
|
-
expect(supervisor).to receive(:add).with(Listen::Silencer, as: :silencer, args: listener)
|
69
82
|
listener.start
|
70
83
|
end
|
71
84
|
|
72
|
-
it
|
73
|
-
expect(supervisor).to receive(:pool).
|
85
|
+
it 'supervises change_pool' do
|
86
|
+
expect(supervisor).to receive(:pool).
|
87
|
+
with(Listen::Change, as: :change_pool, args: listener)
|
88
|
+
|
74
89
|
listener.start
|
75
90
|
end
|
76
91
|
|
77
|
-
it
|
92
|
+
it 'supervises adaper' do
|
78
93
|
Listen::Adapter.stub(:select) { Listen::Adapter::Polling }
|
79
|
-
expect(supervisor).to receive(:add).
|
94
|
+
expect(supervisor).to receive(:add).
|
95
|
+
with(Listen::Adapter::Polling, as: :adapter, args: listener)
|
96
|
+
|
80
97
|
listener.start
|
81
98
|
end
|
82
99
|
|
83
|
-
it
|
84
|
-
expect(supervisor).to receive(:add).
|
100
|
+
it 'supervises record' do
|
101
|
+
expect(supervisor).to receive(:add).
|
102
|
+
with(Listen::Record, as: :record, args: listener)
|
103
|
+
|
85
104
|
listener.start
|
86
105
|
end
|
87
106
|
|
88
|
-
it
|
107
|
+
it 'builds record' do
|
89
108
|
expect(record).to receive(:build)
|
90
109
|
listener.start
|
91
110
|
end
|
92
111
|
|
93
|
-
it
|
112
|
+
it 'sets paused to false' do
|
94
113
|
listener.start
|
95
114
|
expect(listener.paused).to be_false
|
96
115
|
end
|
97
116
|
|
98
|
-
it
|
117
|
+
it 'starts adapter asynchronously' do
|
99
118
|
async_stub = double
|
100
119
|
expect(adapter).to receive(:async) { async_stub }
|
101
120
|
expect(async_stub).to receive(:start)
|
102
121
|
listener.start
|
103
122
|
end
|
104
123
|
|
105
|
-
it
|
124
|
+
it 'starts adapter asynchronously' do
|
106
125
|
async_stub = double
|
107
126
|
expect(adapter).to receive(:async) { async_stub }
|
108
127
|
expect(async_stub).to receive(:start)
|
109
128
|
listener.start
|
110
129
|
end
|
111
130
|
|
112
|
-
it
|
131
|
+
it 'calls block on changes' do
|
113
132
|
foo = double(Pathname, to_s: 'foo', exist?: true, directory?: false)
|
114
133
|
listener.changes = [{ modified: foo }]
|
115
134
|
block_stub = double('block')
|
@@ -120,96 +139,96 @@ describe Listen::Listener do
|
|
120
139
|
end
|
121
140
|
end
|
122
141
|
|
123
|
-
describe
|
124
|
-
it
|
142
|
+
describe '#stop' do
|
143
|
+
it 'terminates supervisor' do
|
125
144
|
listener.supervisor = supervisor
|
126
145
|
expect(supervisor).to receive(:terminate)
|
127
146
|
listener.stop
|
128
147
|
end
|
129
148
|
end
|
130
149
|
|
131
|
-
describe
|
132
|
-
it
|
150
|
+
describe '#pause' do
|
151
|
+
it 'sets paused to true' do
|
133
152
|
listener.pause
|
134
153
|
expect(listener.paused).to be_true
|
135
154
|
end
|
136
155
|
end
|
137
156
|
|
138
|
-
describe
|
139
|
-
it
|
157
|
+
describe '#unpause' do
|
158
|
+
it 'builds record' do
|
140
159
|
expect(record).to receive(:build)
|
141
160
|
listener.unpause
|
142
161
|
end
|
143
162
|
|
144
|
-
it
|
163
|
+
it 'sets paused to false' do
|
145
164
|
record.stub(:build)
|
146
165
|
listener.unpause
|
147
166
|
expect(listener.paused).to be_false
|
148
167
|
end
|
149
168
|
end
|
150
169
|
|
151
|
-
describe
|
152
|
-
it
|
170
|
+
describe '#paused?' do
|
171
|
+
it 'returns true when paused' do
|
153
172
|
listener.paused = true
|
154
173
|
expect(listener).to be_paused
|
155
174
|
end
|
156
|
-
it
|
175
|
+
it 'returns false when not paused (nil)' do
|
157
176
|
listener.paused = nil
|
158
177
|
expect(listener).not_to be_paused
|
159
178
|
end
|
160
|
-
it
|
179
|
+
it 'returns false when not paused (false)' do
|
161
180
|
listener.paused = false
|
162
181
|
expect(listener).not_to be_paused
|
163
182
|
end
|
164
183
|
end
|
165
184
|
|
166
|
-
describe
|
167
|
-
it
|
185
|
+
describe '#listen?' do
|
186
|
+
it 'returns true when not paused (false)' do
|
168
187
|
listener.paused = false
|
169
188
|
listener.stopping = false
|
170
189
|
expect(listener.listen?).to be_true
|
171
190
|
end
|
172
|
-
it
|
191
|
+
it 'returns false when not paused (nil)' do
|
173
192
|
listener.paused = nil
|
174
193
|
listener.stopping = false
|
175
194
|
expect(listener.listen?).to be_false
|
176
195
|
end
|
177
|
-
it
|
196
|
+
it 'returns false when paused' do
|
178
197
|
listener.paused = true
|
179
198
|
listener.stopping = false
|
180
199
|
expect(listener.listen?).to be_false
|
181
200
|
end
|
182
|
-
it
|
201
|
+
it 'returns false when stopped' do
|
183
202
|
listener.paused = false
|
184
203
|
listener.stopping = true
|
185
204
|
expect(listener.listen?).to be_false
|
186
205
|
end
|
187
206
|
end
|
188
207
|
|
189
|
-
describe
|
208
|
+
describe '#ignore' do
|
190
209
|
let(:new_silencer) { double(Listen::Silencer) }
|
191
210
|
before { Celluloid::Actor.stub(:[]=) }
|
192
211
|
|
193
|
-
it
|
212
|
+
it 'resets silencer actor' do
|
194
213
|
expect(Listen::Silencer).to receive(:new).with(listener) { new_silencer }
|
195
214
|
expect(registry).to receive(:[]=).with(:silencer, new_silencer)
|
196
215
|
listener.ignore(/foo/)
|
197
216
|
end
|
198
217
|
|
199
|
-
context
|
218
|
+
context 'with existing ignore options' do
|
200
219
|
let(:options) { { ignore: /bar/ } }
|
201
220
|
|
202
|
-
it
|
221
|
+
it 'adds up to existing ignore options' do
|
203
222
|
expect(Listen::Silencer).to receive(:new).with(listener)
|
204
223
|
listener.ignore(/foo/)
|
205
224
|
expect(listener.options).to include(ignore: [/bar/, /foo/])
|
206
225
|
end
|
207
226
|
end
|
208
227
|
|
209
|
-
context
|
228
|
+
context 'with existing ignore options (array)' do
|
210
229
|
let(:options) { { ignore: [/bar/] } }
|
211
230
|
|
212
|
-
it
|
231
|
+
it 'adds up to existing ignore options' do
|
213
232
|
expect(Listen::Silencer).to receive(:new).with(listener)
|
214
233
|
listener.ignore(/foo/)
|
215
234
|
expect(listener.options).to include(ignore: [[/bar/], /foo/])
|
@@ -217,31 +236,31 @@ describe Listen::Listener do
|
|
217
236
|
end
|
218
237
|
end
|
219
238
|
|
220
|
-
describe
|
239
|
+
describe '#ignore!' do
|
221
240
|
let(:new_silencer) { double(Listen::Silencer) }
|
222
241
|
before { Celluloid::Actor.stub(:[]=) }
|
223
242
|
|
224
|
-
it
|
243
|
+
it 'resets silencer actor' do
|
225
244
|
expect(Listen::Silencer).to receive(:new).with(listener) { new_silencer }
|
226
245
|
expect(registry).to receive(:[]=).with(:silencer, new_silencer)
|
227
246
|
listener.ignore!(/foo/)
|
228
247
|
expect(listener.options).to include(ignore!: /foo/)
|
229
248
|
end
|
230
249
|
|
231
|
-
context
|
250
|
+
context 'with existing ignore! options' do
|
232
251
|
let(:options) { { ignore!: /bar/ } }
|
233
252
|
|
234
|
-
it
|
253
|
+
it 'overwrites existing ignore options' do
|
235
254
|
expect(Listen::Silencer).to receive(:new).with(listener)
|
236
255
|
listener.ignore!([/foo/])
|
237
256
|
expect(listener.options).to include(ignore!: [/foo/])
|
238
257
|
end
|
239
258
|
end
|
240
259
|
|
241
|
-
context
|
260
|
+
context 'with existing ignore options' do
|
242
261
|
let(:options) { { ignore: /bar/ } }
|
243
262
|
|
244
|
-
it
|
263
|
+
it 'deletes ignore options' do
|
245
264
|
expect(Listen::Silencer).to receive(:new).with(listener)
|
246
265
|
listener.ignore!([/foo/])
|
247
266
|
expect(listener.options).to_not include(ignore: /bar/)
|
@@ -249,20 +268,20 @@ describe Listen::Listener do
|
|
249
268
|
end
|
250
269
|
end
|
251
270
|
|
252
|
-
describe
|
271
|
+
describe '#only' do
|
253
272
|
let(:new_silencer) { double(Listen::Silencer) }
|
254
273
|
before { Celluloid::Actor.stub(:[]=) }
|
255
274
|
|
256
|
-
it
|
275
|
+
it 'resets silencer actor' do
|
257
276
|
expect(Listen::Silencer).to receive(:new).with(listener) { new_silencer }
|
258
277
|
expect(registry).to receive(:[]=).with(:silencer, new_silencer)
|
259
278
|
listener.only(/foo/)
|
260
279
|
end
|
261
280
|
|
262
|
-
context
|
281
|
+
context 'with existing only options' do
|
263
282
|
let(:options) { { only: /bar/ } }
|
264
283
|
|
265
|
-
it
|
284
|
+
it 'overwrites existing ignore options' do
|
266
285
|
expect(Listen::Silencer).to receive(:new).with(listener)
|
267
286
|
listener.only([/foo/])
|
268
287
|
expect(listener.options).to include(only: [/foo/])
|
@@ -275,28 +294,31 @@ describe Listen::Listener do
|
|
275
294
|
silencer.stub(:silenced?) { false }
|
276
295
|
|
277
296
|
fake_time = 0
|
278
|
-
listener.stub(:sleep)
|
297
|
+
listener.stub(:sleep) do |sec|
|
298
|
+
fake_time += sec
|
299
|
+
listener.stopping = true if fake_time > 1
|
300
|
+
end
|
279
301
|
|
280
|
-
listener.block = proc
|
302
|
+
listener.block = proc do |modified, added, _|
|
281
303
|
expect(modified).to eql(['foo.txt'])
|
282
304
|
expect(added).to eql(['bar.txt'])
|
283
|
-
|
305
|
+
end
|
284
306
|
|
285
307
|
foo = double(Pathname, to_s: 'foo.txt', exist?: true, directory?: false)
|
286
308
|
bar = double(Pathname, to_s: 'bar.txt', exist?: true, directory?: false)
|
287
309
|
|
288
310
|
i = 0
|
289
311
|
listener.stub(:_pop_changes) do
|
290
|
-
i+=1
|
312
|
+
i += 1
|
291
313
|
case i
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
314
|
+
when 1
|
315
|
+
[]
|
316
|
+
when 2
|
317
|
+
[{ modified: foo }]
|
318
|
+
when 3
|
319
|
+
[{ added: bar }]
|
320
|
+
else
|
321
|
+
[]
|
300
322
|
end
|
301
323
|
end
|
302
324
|
|
@@ -343,14 +365,12 @@ describe Listen::Listener do
|
|
343
365
|
expect(smooshed).to eq(modified: ['foo'], added: [], removed: [])
|
344
366
|
end
|
345
367
|
|
346
|
-
context
|
368
|
+
context 'with cookie' do
|
347
369
|
|
348
370
|
it 'recognizes single moved_to as add' do
|
349
371
|
foo = double(Pathname, to_s: 'foo', exist?: true, directory?: false)
|
350
|
-
changes = [
|
351
|
-
|
352
|
-
]
|
353
|
-
expect(silencer).to receive(:silenced?).with(foo, 'File').and_return(false)
|
372
|
+
changes = [{ moved_to: foo , cookie: 4321 }]
|
373
|
+
expect(silencer).to receive(:silenced?).with(foo, 'File') { false }
|
354
374
|
smooshed = listener.send :_smoosh_changes, changes
|
355
375
|
expect(smooshed).to eq(modified: [], added: ['foo'], removed: [])
|
356
376
|
end
|
@@ -360,35 +380,45 @@ describe Listen::Listener do
|
|
360
380
|
bar = double(:bar, to_s: 'bar', exist?: true, directory?: false)
|
361
381
|
changes = [
|
362
382
|
{ moved_from: foo , cookie: 4321 },
|
363
|
-
{ moved_to: bar, cookie: 4321 }
|
383
|
+
{ moved_to: bar, cookie: 4321 }
|
364
384
|
]
|
365
|
-
|
366
|
-
expect(silencer).to receive(:silenced?).
|
385
|
+
|
386
|
+
expect(silencer).to receive(:silenced?).
|
387
|
+
twice.with(foo, 'File') { false }
|
388
|
+
|
389
|
+
expect(silencer).to receive(:silenced?).with(bar, 'File') { false }
|
367
390
|
smooshed = listener.send :_smoosh_changes, changes
|
368
391
|
expect(smooshed).to eq(modified: [], added: ['bar'], removed: [])
|
369
392
|
end
|
370
393
|
|
371
394
|
# Scenario with workaround for editors using rename()
|
372
395
|
it 'recognizes related moved_to with ignored moved_from as modify' do
|
373
|
-
|
396
|
+
|
397
|
+
ignored = double(Pathname,
|
398
|
+
to_s: 'foo',
|
399
|
+
exist?: true,
|
400
|
+
directory?: false)
|
401
|
+
|
374
402
|
foo = double(Pathname, to_s: 'foo', exist?: true, directory?: false)
|
375
403
|
changes = [
|
376
404
|
{ moved_from: ignored, cookie: 4321 },
|
377
|
-
{ moved_to: foo , cookie: 4321 }
|
405
|
+
{ moved_to: foo , cookie: 4321 }
|
378
406
|
]
|
379
|
-
expect(silencer).to receive(:silenced?).with(ignored, 'File')
|
380
|
-
expect(silencer).to receive(:silenced?).with(foo, 'File')
|
407
|
+
expect(silencer).to receive(:silenced?).with(ignored, 'File') { true }
|
408
|
+
expect(silencer).to receive(:silenced?).with(foo, 'File') { false }
|
381
409
|
smooshed = listener.send :_smoosh_changes, changes
|
382
410
|
expect(smooshed).to eq(modified: ['foo'], added: [], removed: [])
|
383
411
|
end
|
384
412
|
end
|
385
413
|
|
386
|
-
context
|
414
|
+
context 'with no cookie' do
|
387
415
|
it 'recognizes properly ignores files' do
|
388
|
-
ignored = double(Pathname,
|
389
|
-
|
390
|
-
|
391
|
-
|
416
|
+
ignored = double(Pathname,
|
417
|
+
to_s: 'foo',
|
418
|
+
exist?: true,
|
419
|
+
directory?: false)
|
420
|
+
|
421
|
+
changes = [{ modified: ignored }]
|
392
422
|
expect(silencer).to receive(:silenced?).with(ignored, 'File') { true }
|
393
423
|
smooshed = listener.send :_smoosh_changes, changes
|
394
424
|
expect(smooshed).to eq(modified: [], added: [], removed: [])
|