listen 2.8.4 → 2.8.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -11
  3. data/lib/listen/adapter/base.rb +8 -4
  4. data/lib/listen/adapter/bsd.rb +8 -25
  5. data/lib/listen/adapter/tcp.rb +2 -1
  6. data/lib/listen/internals/logging.rb +12 -8
  7. data/lib/listen/listener.rb +1 -1
  8. data/lib/listen/version.rb +1 -1
  9. metadata +4 -121
  10. data/.gitignore +0 -28
  11. data/.hound.yml +0 -3
  12. data/.rspec +0 -2
  13. data/.rubocop.yml +0 -20
  14. data/.rubocop_todo.yml +0 -33
  15. data/.travis.yml +0 -15
  16. data/.yardopts +0 -11
  17. data/Gemfile +0 -48
  18. data/Guardfile +0 -16
  19. data/Rakefile +0 -151
  20. data/TROUBLESHOOTING.md +0 -139
  21. data/listen.gemspec +0 -33
  22. data/spec/acceptance/listen_spec.rb +0 -230
  23. data/spec/acceptance/tcp_spec.rb +0 -139
  24. data/spec/lib/listen/adapter/base_spec.rb +0 -31
  25. data/spec/lib/listen/adapter/bsd_spec.rb +0 -14
  26. data/spec/lib/listen/adapter/darwin_spec.rb +0 -145
  27. data/spec/lib/listen/adapter/linux_spec.rb +0 -93
  28. data/spec/lib/listen/adapter/polling_spec.rb +0 -48
  29. data/spec/lib/listen/adapter/tcp_spec.rb +0 -129
  30. data/spec/lib/listen/adapter/windows_spec.rb +0 -14
  31. data/spec/lib/listen/adapter_spec.rb +0 -75
  32. data/spec/lib/listen/change_spec.rb +0 -104
  33. data/spec/lib/listen/directory_spec.rb +0 -180
  34. data/spec/lib/listen/file_spec.rb +0 -252
  35. data/spec/lib/listen/listener_spec.rb +0 -482
  36. data/spec/lib/listen/record_spec.rb +0 -377
  37. data/spec/lib/listen/silencer_spec.rb +0 -100
  38. data/spec/lib/listen/tcp/broadcaster_spec.rb +0 -124
  39. data/spec/lib/listen/tcp/listener_spec.rb +0 -104
  40. data/spec/lib/listen/tcp/message_spec.rb +0 -138
  41. data/spec/lib/listen_spec.rb +0 -52
  42. data/spec/spec_helper.rb +0 -52
  43. data/spec/support/acceptance_helper.rb +0 -275
  44. data/spec/support/fixtures_helper.rb +0 -30
  45. data/spec/support/platform_helper.rb +0 -15
  46. data/vendor/hound/config/style_guides/ruby.yml +0 -259
@@ -1,377 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Listen::Record do
4
- let(:registry) { instance_double(Celluloid::Registry) }
5
-
6
- let(:listener) do
7
- instance_double(Listen::Listener, registry: registry, options: {})
8
- end
9
-
10
- def dir_entries_for(hash)
11
- hash.each do |dir, entries|
12
- allow(::Dir).to receive(:entries).with(dir) { entries }
13
- end
14
- end
15
-
16
- def real_directory(hash)
17
- dir_entries_for(hash)
18
- hash.each do |dir, _|
19
- realpath(dir)
20
- end
21
- end
22
-
23
- def file(path)
24
- allow(::Dir).to receive(:entries).with(path).and_raise(Errno::ENOTDIR)
25
- path
26
- end
27
-
28
- def lstat(path, stat = nil)
29
- stat ||= instance_double(::File::Stat, mtime: 2.3, mode: 0755)
30
- allow(::File).to receive(:lstat).with(path).and_return(stat)
31
- stat
32
- end
33
-
34
- def realpath(path)
35
- allow(::File).to receive(:realpath).with(path).and_return(path)
36
- path
37
- end
38
-
39
- def symlink(hash_or_dir)
40
- if String === hash_or_dir
41
- allow(::File).to receive(:realpath).with(hash_or_dir).
42
- and_return(hash_or_dir)
43
- else
44
- hash_or_dir.each do |dir, real_path|
45
- allow(::File).to receive(:realpath).with(dir).and_return(real_path)
46
- end
47
- end
48
- end
49
-
50
- let(:record) { Listen::Record.new(listener) }
51
- let(:dir) { instance_double(Pathname, to_s: '/dir') }
52
-
53
- describe '#update_file' do
54
- context 'with path in watched dir' do
55
- it 'sets path by spliting dirname and basename' do
56
- record.update_file(dir, 'file.rb', mtime: 1.1)
57
- expect(record.paths['/dir']).to eq('file.rb' => { mtime: 1.1 })
58
- end
59
-
60
- it 'sets path and keeps old data not overwritten' do
61
- record.update_file(dir, 'file.rb', foo: 1, bar: 2)
62
- record.update_file(dir, 'file.rb', foo: 3)
63
- watched_dir = record.paths['/dir']
64
- expect(watched_dir).to eq('file.rb' => { foo: 3, bar: 2 })
65
- end
66
- end
67
-
68
- context 'with subdir path' do
69
- it 'sets path by spliting dirname and basename' do
70
- record.update_file(dir, 'path/file.rb', mtime: 1.1)
71
- expect(record.paths['/dir']['path']).to eq('file.rb' => { mtime: 1.1 })
72
- end
73
-
74
- it 'sets path and keeps old data not overwritten' do
75
- record.update_file(dir, 'path/file.rb', foo: 1, bar: 2)
76
- record.update_file(dir, 'path/file.rb', foo: 3)
77
- file_data = record.paths['/dir']['path']['file.rb']
78
- expect(file_data).to eq(foo: 3, bar: 2)
79
- end
80
- end
81
- end
82
-
83
- describe '#add_dir' do
84
- it 'sets itself when .' do
85
- record.add_dir(dir, '.')
86
- expect(record.paths['/dir']).to eq({})
87
- end
88
-
89
- it 'sets itself when nil' do
90
- record.add_dir(dir, nil)
91
- expect(record.paths['/dir']).to eq({})
92
- end
93
-
94
- it 'sets itself when empty' do
95
- record.add_dir(dir, '')
96
- expect(record.paths['/dir']).to eq({})
97
- end
98
-
99
- it 'correctly sets new directory data' do
100
- record.add_dir(dir, 'path/subdir')
101
- expect(record.paths['/dir']).to eq('path/subdir' => {})
102
- end
103
-
104
- it 'sets path and keeps old data not overwritten' do
105
- record.add_dir(dir, 'path/subdir')
106
- record.update_file(dir, 'path/subdir/file.rb', mtime: 1.1)
107
- record.add_dir(dir, 'path/subdir')
108
- record.update_file(dir, 'path/subdir/file2.rb', mtime: 1.2)
109
- record.add_dir(dir, 'path/subdir')
110
-
111
- watched = record.paths['/dir']
112
- expect(watched.keys).to eq ['path/subdir']
113
- expect(watched['path/subdir'].keys).to eq %w(file.rb file2.rb)
114
-
115
- subdir = watched['path/subdir']
116
- expect(subdir['file.rb']).to eq(mtime: 1.1)
117
- expect(subdir['file2.rb']).to eq(mtime: 1.2)
118
- end
119
- end
120
-
121
- describe '#unset_path' do
122
- context 'within watched dir' do
123
- context 'when path is present' do
124
- before { record.update_file(dir, 'file.rb', mtime: 1.1) }
125
-
126
- it 'unsets path' do
127
- record.unset_path(dir, 'file.rb')
128
- expect(record.paths).to eq('/dir' => {})
129
- end
130
- end
131
-
132
- context 'when path not present' do
133
- it 'unsets path' do
134
- record.unset_path(dir, 'file.rb')
135
- expect(record.paths).to eq('/dir' => {})
136
- end
137
- end
138
- end
139
-
140
- context 'within subdir' do
141
- context 'when path is present' do
142
- before { record.update_file(dir, 'path/file.rb', mtime: 1.1) }
143
-
144
- it 'unsets path' do
145
- record.unset_path(dir, 'path/file.rb')
146
- expect(record.paths).to eq('/dir' => { 'path' => {} })
147
- end
148
- end
149
-
150
- context 'when path not present' do
151
- it 'unsets path' do
152
- record.unset_path(dir, 'path/file.rb')
153
- expect(record.paths).to eq('/dir' => {})
154
- end
155
- end
156
- end
157
- end
158
-
159
- describe '#file_data' do
160
- context 'with path in watched dir' do
161
- context 'when path is present' do
162
- before { record.update_file(dir, 'file.rb', mtime: 1.1) }
163
-
164
- it 'returns file data' do
165
- expect(record.file_data(dir, 'file.rb')).to eq(mtime: 1.1)
166
- end
167
- end
168
-
169
- context 'path not present' do
170
- it 'return empty hash' do
171
- expect(record.file_data(dir, 'file.rb')).to be_empty
172
- end
173
- end
174
- end
175
-
176
- context 'with path in subdir' do
177
- context 'when path is present' do
178
- before { record.update_file(dir, 'path/file.rb', mtime: 1.1) }
179
-
180
- it 'returns file data' do
181
- expected = { mtime: 1.1 }
182
- expect(record.file_data(dir, 'path/file.rb')).to eq expected
183
- end
184
- end
185
-
186
- context 'path not present' do
187
- it 'return empty hash' do
188
- expect(record.file_data(dir, 'path/file.rb')).to be_empty
189
- end
190
- end
191
- end
192
- end
193
-
194
- describe '#dir_entries' do
195
- context 'in watched dir' do
196
- subject { record.dir_entries(dir, '.') }
197
-
198
- context 'with no entries' do
199
- it { should be_empty }
200
- end
201
-
202
- context 'with file.rb in record' do
203
- before { record.update_file(dir, 'file.rb', mtime: 1.1) }
204
- it { should eq('file.rb' => { mtime: 1.1 }) }
205
- end
206
-
207
- context 'with subdir/file.rb in record' do
208
- before { record.update_file(dir, 'subdir/file.rb', mtime: 1.1) }
209
- it { should eq('subdir' => {}) }
210
- end
211
- end
212
-
213
- context 'in subdir /path' do
214
- subject { record.dir_entries(dir, 'path') }
215
-
216
- context 'with no entries' do
217
- it { should be_empty }
218
- end
219
-
220
- context 'with path/file.rb already in record' do
221
- before { record.update_file(dir, 'path/file.rb', mtime: 1.1) }
222
- it { should eq('file.rb' => { mtime: 1.1 }) }
223
- end
224
- end
225
- end
226
-
227
- describe '#build' do
228
- let(:dir1) { Pathname('/dir1') }
229
- let(:dir2) { Pathname('/dir2') }
230
-
231
- let(:directories) { [dir1, dir2] }
232
-
233
- before do
234
- allow(listener).to receive(:directories) { directories }
235
-
236
- stubs = {
237
- ::File => %w(lstat realpath),
238
- ::Dir => %w(entries exist?)
239
- }
240
-
241
- stubs.each do |klass, meths|
242
- meths.each do |meth|
243
- allow(klass).to receive(meth.to_sym) do |*args|
244
- fail "stub called: #{klass}.#{meth}(#{args.map(&:inspect) * ', '})"
245
- end
246
- end
247
- end
248
- end
249
-
250
- it 're-inits paths' do
251
- real_directory('/dir1' => [])
252
- real_directory('/dir2' => [])
253
-
254
- record.update_file(dir, 'path/file.rb', mtime: 1.1)
255
- record.build
256
- expect(record.paths).to eq('/dir1' => {}, '/dir2' => {})
257
- expect(record.file_data(dir, 'path/file.rb')).to be_empty
258
- end
259
-
260
- let(:foo_stat) { instance_double(::File::Stat, mtime: 1.0, mode: 0644) }
261
- let(:bar_stat) { instance_double(::File::Stat, mtime: 2.3, mode: 0755) }
262
-
263
- context 'with no subdirs' do
264
- before do
265
- real_directory('/dir1' => %w(foo bar))
266
- lstat(file('/dir1/foo'), foo_stat)
267
- lstat(file('/dir1/bar'), bar_stat)
268
- real_directory('/dir2' => [])
269
- end
270
-
271
- it 'builds record' do
272
- record.build
273
- expect(record.paths.keys).to eq %w( /dir1 /dir2 )
274
- expect(record.paths['/dir1']).
275
- to eq(
276
- 'foo' => { mtime: 1.0, mode: 0644 },
277
- 'bar' => { mtime: 2.3, mode: 0755 })
278
- end
279
- end
280
-
281
- context 'with subdir containing files' do
282
- before do
283
- real_directory('/dir1' => %w(foo))
284
- real_directory('/dir1/foo' => %w(bar))
285
- lstat(file('/dir1/foo/bar'))
286
- real_directory('/dir2' => [])
287
- end
288
-
289
- it 'builds record' do
290
- record.build
291
- expect(record.paths.keys).to eq %w( /dir1 /dir2 )
292
- expect(record.paths['/dir1']).
293
- to eq('foo' => { 'bar' => { mtime: 2.3, mode: 0755 } })
294
- expect(record.paths['/dir2']).to eq({})
295
- end
296
- end
297
-
298
- context 'with subdir containing dirs' do
299
- before do
300
- real_directory('/dir1' => %w(foo))
301
- real_directory('/dir1/foo' => %w(bar baz))
302
- real_directory('/dir1/foo/bar' => [])
303
- real_directory('/dir1/foo/baz' => [])
304
- real_directory('/dir2' => [])
305
-
306
- allow(::File).to receive(:realpath) { |path| path }
307
- end
308
-
309
- it 'builds record' do
310
- record.build
311
- expect(record.paths.keys).to eq %w( /dir1 /dir2 )
312
- expect(record.paths['/dir1']).
313
- to eq(
314
- 'foo' => {},
315
- 'foo/bar' => {},
316
- 'foo/baz' => {}
317
- )
318
- expect(record.paths['/dir2']).to eq({})
319
- end
320
- end
321
-
322
- context 'with subdir containing symlink to parent' do
323
- subject { record.paths }
324
- before do
325
- real_directory('/dir1' => %w(foo))
326
- dir_entries_for('/dir1/foo' => %w(dir1))
327
- symlink('/dir1/foo' => '/dir1')
328
-
329
- real_directory('/dir2' => [])
330
- end
331
-
332
- it 'shows a warning' do
333
- expect(STDERR).to receive(:puts).
334
- with(/directory is already being watched/)
335
-
336
- record.build
337
- # expect { record.build }.
338
- # to raise_error(RuntimeError, /Failed due to looped symlinks/)
339
- end
340
- end
341
-
342
- context 'with a normal symlinked directory to another' do
343
- subject { record.paths }
344
-
345
- before do
346
- real_directory('/dir1' => %w(foo))
347
-
348
- symlink('/dir1/foo' => '/dir2')
349
- dir_entries_for('/dir1/foo' => %w(bar))
350
- lstat(realpath(file('/dir1/foo/bar')))
351
-
352
- real_directory('/dir2' => %w(bar))
353
- lstat(file('/dir2/bar'))
354
- end
355
-
356
- it 'shows message' do
357
- expect(STDERR).to_not receive(:puts)
358
- record.build
359
- end
360
- end
361
-
362
- context 'with subdir containing symlinked file' do
363
- subject { record.paths }
364
- before do
365
- real_directory('/dir1' => %w(foo))
366
- lstat(file('/dir1/foo'))
367
- real_directory('/dir2' => [])
368
- end
369
-
370
- it 'shows a warning' do
371
- expect(STDERR).to_not receive(:puts)
372
-
373
- record.build
374
- end
375
- end
376
- end
377
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec::Matchers.define :accept do |type, path|
4
- match { |actual| !actual.silenced?(Pathname(path), type) }
5
- end
6
-
7
- describe Listen::Silencer do
8
- let(:options) { {} }
9
- before { subject.configure(options) }
10
-
11
- describe '#silenced?' do
12
- it { should accept(:file, Pathname('some_dir') + 'some_file.rb') }
13
-
14
- context 'with default ignore' do
15
- hidden_ignored = %w(.git .svn .hg .rbx .bundle)
16
- other_ignored = %w(bundle vendor/bundle log tmp vendor/ruby)
17
- (hidden_ignored + other_ignored).each do |dir|
18
- it { should_not accept(:dir, dir) }
19
- it { should accept(:dir, "#{dir}foo") }
20
- it { should accept(:dir, "foo#{dir}") }
21
- end
22
-
23
- ignored = %w(.DS_Store foo.tmp foo~)
24
-
25
- # Gedit swap files
26
- ignored += %w(.goutputstream-S3FBGX)
27
-
28
- # Kate editor swap files
29
- ignored += %w(foo.rbo54321.new foo.rbB22583.new foo.rb.kate-swp)
30
-
31
- # Intellij swap files
32
- ignored += %w(foo.rb___jb_bak___ foo.rb___jb_old___)
33
-
34
- # Vim swap files
35
- ignored += %w(foo.swp foo.swx foo.swpx 4913)
36
-
37
- # sed temp files
38
- ignored += %w(sedq7eVAR sed86w1kB)
39
-
40
- ignored.each do |path|
41
- it { should_not accept(:file, path) }
42
- end
43
-
44
- %w(
45
- foo.tmpl file.new file54321.new a.swf 14913 49131
46
-
47
- sed_ABCDE
48
- sedabcdefg
49
- .sedq7eVAR
50
- foo.sedq7eVAR
51
- sedatives
52
- sediments
53
- sedan2014
54
-
55
- ).each do |path|
56
- it { should accept(:file, path) }
57
- end
58
- end
59
-
60
- context 'when ignoring *.pid' do
61
- let(:options) { { ignore: /\.pid$/ } }
62
- it { should_not accept(:file, 'foo.pid') }
63
- end
64
-
65
- context 'when ignoring foo/bar* and *.pid' do
66
- let(:options) { { ignore: [/^foo\/bar/, /\.pid$/] } }
67
- it { should_not accept(:file, 'foo/bar/baz') }
68
- it { should_not accept(:file, 'foo.pid') }
69
- end
70
-
71
- context 'when ignoring only *.pid' do
72
- let(:options) { { ignore!: /\.pid$/ } }
73
- it { should_not accept(:file, 'foo.pid') }
74
- it { should accept(:file, '.git') }
75
- end
76
-
77
- context 'when accepting only *foo*' do
78
- let(:options) { { only: /foo/ } }
79
- it { should accept(:file, 'foo') }
80
- it { should_not accept(:file, 'bar') }
81
- end
82
-
83
- context 'when accepting only foo/* and *.txt' do
84
- let(:options) { { only: [/^foo\//, /\.txt$/] } }
85
- it { should accept(:file, 'foo/bar.rb') }
86
- it { should accept(:file, 'bar.txt') }
87
- it { should_not accept(:file, 'bar/baz.rb') }
88
- it { should_not accept(:file, 'bar.rb') }
89
- end
90
-
91
- context 'when accepting only *.pid' do
92
- context 'when ignoring bar*' do
93
- let(:options) { { only: /\.pid$/, ignore: /^bar/ } }
94
- it { should_not accept(:file, 'foo.rb') }
95
- it { should_not accept(:file, 'bar.pid') }
96
- it { should accept(:file, 'foo.pid') }
97
- end
98
- end
99
- end
100
- end