listen 2.7.4 → 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +232 -0
  3. data/.travis.yml +6 -3
  4. data/Gemfile +9 -1
  5. data/Guardfile +6 -1
  6. data/README.md +17 -4
  7. data/lib/listen.rb +9 -4
  8. data/lib/listen/adapter.rb +5 -7
  9. data/lib/listen/adapter/base.rb +8 -5
  10. data/lib/listen/adapter/bsd.rb +58 -21
  11. data/lib/listen/adapter/darwin.rb +2 -4
  12. data/lib/listen/adapter/linux.rb +20 -10
  13. data/lib/listen/adapter/polling.rb +0 -2
  14. data/lib/listen/adapter/tcp.rb +6 -5
  15. data/lib/listen/adapter/windows.rb +8 -6
  16. data/lib/listen/change.rb +1 -2
  17. data/lib/listen/cli.rb +25 -22
  18. data/lib/listen/directory.rb +8 -6
  19. data/lib/listen/listener.rb +25 -19
  20. data/lib/listen/record.rb +4 -2
  21. data/lib/listen/silencer.rb +55 -25
  22. data/lib/listen/tcp.rb +9 -0
  23. data/lib/listen/tcp/broadcaster.rb +0 -2
  24. data/lib/listen/tcp/listener.rb +13 -8
  25. data/lib/listen/tcp/message.rb +0 -2
  26. data/lib/listen/version.rb +1 -1
  27. data/listen.gemspec +4 -3
  28. data/spec/acceptance/listen_spec.rb +190 -109
  29. data/spec/acceptance/tcp_spec.rb +28 -26
  30. data/spec/lib/listen/adapter/base_spec.rb +14 -12
  31. data/spec/lib/listen/adapter/bsd_spec.rb +5 -2
  32. data/spec/lib/listen/adapter/darwin_spec.rb +5 -2
  33. data/spec/lib/listen/adapter/linux_spec.rb +40 -25
  34. data/spec/lib/listen/adapter/polling_spec.rb +29 -14
  35. data/spec/lib/listen/adapter/tcp_spec.rb +24 -6
  36. data/spec/lib/listen/adapter/windows_spec.rb +5 -2
  37. data/spec/lib/listen/adapter_spec.rb +20 -17
  38. data/spec/lib/listen/change_spec.rb +36 -26
  39. data/spec/lib/listen/directory_spec.rb +128 -71
  40. data/spec/lib/listen/file_spec.rb +67 -34
  41. data/spec/lib/listen/listener_spec.rb +135 -105
  42. data/spec/lib/listen/record_spec.rb +32 -29
  43. data/spec/lib/listen/silencer_spec.rb +78 -56
  44. data/spec/lib/listen/tcp/broadcaster_spec.rb +3 -2
  45. data/spec/lib/listen/tcp/listener_spec.rb +17 -11
  46. data/spec/lib/listen/tcp/message_spec.rb +1 -1
  47. data/spec/lib/listen_spec.rb +18 -6
  48. data/spec/spec_helper.rb +5 -1
  49. data/spec/support/acceptance_helper.rb +3 -3
  50. data/spec/support/fixtures_helper.rb +10 -9
  51. metadata +17 -15
@@ -5,8 +5,8 @@ describe Listen::Adapter::Windows do
5
5
  let(:listener) { double(Listen::Listener) }
6
6
  let(:adapter) { described_class.new(listener) }
7
7
 
8
- describe ".usable?" do
9
- it "returns always true" do
8
+ describe '.usable?' do
9
+ it 'returns always true' do
10
10
  expect(described_class).to be_usable
11
11
  end
12
12
 
@@ -34,4 +34,7 @@ describe Listen::Adapter::Windows do
34
34
  expect(described_class).to_not be_usable
35
35
  end
36
36
  end
37
+
38
+ specify { expect(described_class).to be_local_fs }
39
+
37
40
  end
@@ -1,59 +1,61 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Listen::Adapter do
4
+
4
5
  let(:listener) { double(Listen::Listener, options: {}) }
5
- before {
6
+ before do
6
7
  Listen::Adapter::BSD.stub(:usable?) { false }
7
8
  Listen::Adapter::Darwin.stub(:usable?) { false }
8
9
  Listen::Adapter::Linux.stub(:usable?) { false }
9
10
  Listen::Adapter::Windows.stub(:usable?) { false }
10
- }
11
+ end
11
12
 
12
- describe ".select" do
13
+ describe '.select' do
13
14
  it 'returns TCP adapter when requested' do
14
15
  klass = Listen::Adapter.select(force_tcp: true)
15
16
  expect(klass).to eq Listen::Adapter::TCP
16
17
  end
17
18
 
18
- it "returns Polling adapter if forced" do
19
+ it 'returns Polling adapter if forced' do
19
20
  klass = Listen::Adapter.select(force_polling: true)
20
21
  expect(klass).to eq Listen::Adapter::Polling
21
22
  end
22
23
 
23
- it "returns BSD adapter when usable" do
24
+ it 'returns BSD adapter when usable' do
24
25
  Listen::Adapter::BSD.stub(:usable?) { true }
25
26
  klass = Listen::Adapter.select
26
27
  expect(klass).to eq Listen::Adapter::BSD
27
28
  end
28
29
 
29
- it "returns Darwin adapter when usable" do
30
+ it 'returns Darwin adapter when usable' do
30
31
  Listen::Adapter::Darwin.stub(:usable?) { true }
31
32
  klass = Listen::Adapter.select
32
33
  expect(klass).to eq Listen::Adapter::Darwin
33
34
  end
34
35
 
35
- it "returns Linux adapter when usable" do
36
+ it 'returns Linux adapter when usable' do
36
37
  Listen::Adapter::Linux.stub(:usable?) { true }
37
38
  klass = Listen::Adapter.select
38
39
  expect(klass).to eq Listen::Adapter::Linux
39
40
  end
40
41
 
41
- it "returns Windows adapter when usable" do
42
+ it 'returns Windows adapter when usable' do
42
43
  Listen::Adapter::Windows.stub(:usable?) { true }
43
44
  klass = Listen::Adapter.select
44
45
  expect(klass).to eq Listen::Adapter::Windows
45
46
  end
46
47
 
47
- context "no usable adapters" do
48
+ context 'no usable adapters' do
48
49
  before { Kernel.stub(:warn) }
49
50
 
50
- it "returns Polling adapter" do
51
+ it 'returns Polling adapter' do
51
52
  klass = Listen::Adapter.select(force_polling: true)
52
53
  expect(klass).to eq Listen::Adapter::Polling
53
54
  end
54
55
 
55
- it "warns polling fallback with default message" do
56
- expect(Kernel).to receive(:warn).with("[Listen warning]:\n #{described_class::POLLING_FALLBACK_MESSAGE}")
56
+ it 'warns polling fallback with default message' do
57
+ msg = described_class::POLLING_FALLBACK_MESSAGE
58
+ expect(Kernel).to receive(:warn).with("[Listen warning]:\n #{msg}")
57
59
  Listen::Adapter.select
58
60
  end
59
61
 
@@ -62,11 +64,12 @@ describe Listen::Adapter do
62
64
  Listen::Adapter.select(polling_fallback_message: false)
63
65
  end
64
66
 
65
- it "warns polling fallback with custom message if set" do
66
- expect(Kernel).to receive(:warn).with("[Listen warning]:\n custom fallback message")
67
- Listen::Adapter.select(polling_fallback_message: 'custom fallback message')
67
+ it 'warns polling fallback with custom message if set' do
68
+ expected_msg = "[Listen warning]:\n custom fallback message"
69
+ expect(Kernel).to receive(:warn).with(expected_msg)
70
+ msg = 'custom fallback message'
71
+ Listen::Adapter.select(polling_fallback_message: msg)
68
72
  end
69
73
  end
70
- end
71
-
74
+ end
72
75
  end
@@ -4,64 +4,72 @@ describe Listen::Change do
4
4
  let(:change) { Listen::Change.new(listener) }
5
5
  let(:registry) { double(Celluloid::Registry) }
6
6
  let(:listener) { double(Listen::Listener, registry: registry, options: {}) }
7
- let(:listener_changes) { double("listener_changes") }
8
- before {
7
+ let(:listener_changes) { double('listener_changes') }
8
+ before do
9
9
  listener.stub(:changes) { listener_changes }
10
- }
10
+ end
11
11
 
12
- describe "#change" do
12
+ describe '#change' do
13
13
  let(:silencer) { double('Listen::Silencer', silenced?: false) }
14
14
  before { registry.stub(:[]).with(:silencer) { silencer } }
15
15
 
16
- context "file path" do
17
- context "with known change" do
18
- it "notifies change directly to listener" do
19
- expect(listener_changes).to receive(:<<).with(modified: Pathname.new('file_path'))
20
- change.change(Pathname.new('file_path'), type: 'File', change: :modified)
16
+ context 'file path' do
17
+ context 'with known change' do
18
+ it 'notifies change directly to listener' do
19
+ expect(listener_changes).to receive(:<<).
20
+ with(modified: Pathname.new('file_path'))
21
+
22
+ options = { type: 'File', change: :modified }
23
+ change.change(Pathname.new('file_path'), options)
21
24
  end
22
25
 
23
26
  it "doesn't notify to listener if path is silenced" do
24
- # expect(silencer).to receive(:silenced?).with('file_path', 'File').and_return(true)
25
27
  expect(silencer).to receive(:silenced?).and_return(true)
26
28
  expect(listener_changes).to_not receive(:<<)
27
29
 
28
- change.change(Pathname.new('file_path'), type: 'File', change: :modified)
30
+ options = { type: 'File', change: :modified }
31
+ change.change(Pathname.new('file_path'), options)
29
32
  end
30
33
  end
31
34
 
32
- context "with unknown change" do
35
+ context 'with unknown change' do
33
36
  let(:file) { double('Listen::File') }
34
37
  before { Listen::File.stub(:new) { file } }
35
38
 
36
- it "calls Listen::File#change" do
37
- expect(Listen::File).to receive(:new).with(listener, Pathname.new('file_path')) { file }
39
+ it 'calls Listen::File#change' do
40
+ expect(Listen::File).to receive(:new).
41
+ with(listener, Pathname.new('file_path')) { file }
42
+
38
43
  expect(file).to receive(:change)
39
44
  change.change(Pathname.new('file_path'), type: 'File')
40
45
  end
41
46
 
42
47
  it "doesn't call Listen::File#change if path is silenced" do
43
- expect(silencer).to receive(:silenced?).with(Pathname.new('file_path'), 'File').and_return(true)
48
+ expect(silencer).to receive(:silenced?).
49
+ with(Pathname.new('file_path'), 'File').and_return(true)
50
+
44
51
  expect(Listen::File).to_not receive(:new)
45
52
 
46
53
  change.change(Pathname.new('file_path'), type: 'File')
47
54
  end
48
55
 
49
- context "that returns a change" do
56
+ context 'that returns a change' do
50
57
  before { file.stub(:change) { :modified } }
51
58
 
52
- context "listener listen" do
59
+ context 'listener listen' do
53
60
  before { listener.stub(:listen?) { true } }
54
61
 
55
- it "notifies change to listener" do
62
+ it 'notifies change to listener' do
56
63
  file_path = double(Pathname, to_s: 'file_path', exist?: true)
57
64
  expect(listener_changes).to receive(:<<).with(modified: file_path)
58
65
  change.change(file_path, type: 'File')
59
66
  end
60
67
 
61
- context "silence option" do
62
- it "notifies change to listener" do
68
+ context 'silence option' do
69
+ it 'notifies change to listener' do
63
70
  expect(listener_changes).to_not receive(:<<)
64
- change.change(Pathname.new('file_path'), type: 'File', silence: true)
71
+ options = { type: 'File', silence: true }
72
+ change.change(Pathname.new('file_path'), options)
65
73
  end
66
74
  end
67
75
  end
@@ -69,14 +77,14 @@ describe Listen::Change do
69
77
  context "listener doesn't listen" do
70
78
  before { listener.stub(:listen?) { false } }
71
79
 
72
- it "notifies change to listener" do
80
+ it 'notifies change to listener' do
73
81
  expect(listener_changes).to_not receive(:<<)
74
82
  change.change(Pathname.new('file_path'), type: 'File')
75
83
  end
76
84
  end
77
85
  end
78
86
 
79
- context "that returns no change" do
87
+ context 'that returns no change' do
80
88
  before { file.stub(:change) { nil } }
81
89
 
82
90
  it "doesn't notifies no change" do
@@ -87,13 +95,15 @@ describe Listen::Change do
87
95
  end
88
96
  end
89
97
 
90
- context "directory path" do
98
+ context 'directory path' do
91
99
  let(:dir) { double(Listen::Directory) }
92
100
  let(:dir_options) { { type: 'Dir', recursive: true } }
93
101
  before { Listen::Directory.stub(:new) { dir } }
94
102
 
95
- it "calls Listen::Directory#scan" do
96
- expect(Listen::Directory).to receive(:new).with(listener, Pathname.new('dir_path'), dir_options) { dir }
103
+ it 'calls Listen::Directory#scan' do
104
+ expect(Listen::Directory).to receive(:new).
105
+ with(listener, Pathname.new('dir_path'), dir_options) { dir }
106
+
97
107
  expect(dir).to receive(:scan)
98
108
  change.change(Pathname.new('dir_path'), dir_options)
99
109
  end
@@ -3,18 +3,22 @@ require 'spec_helper'
3
3
  describe Listen::Directory do
4
4
  let(:registry) { double(Celluloid::Registry) }
5
5
  let(:listener) { double(Listen::Listener, registry: registry, options: {}) }
6
- let(:record) { double(Listen::Record, async: double(set_path: true, unset_path: true)) }
6
+
7
+ let(:record) do
8
+ double(Listen::Record, async: double(set_path: true, unset_path: true))
9
+ end
10
+
7
11
  let(:change_pool) { double(Listen::Change) }
8
12
  let(:change_pool_async) { double('ChangePoolAsync') }
9
13
  let(:path) { Pathname.new(Dir.pwd) }
10
- around { |example| fixtures { |path| example.run } }
11
- before {
14
+ around { |example| fixtures { example.run } }
15
+ before do
12
16
  change_pool.stub(:async) { change_pool_async }
13
17
  registry.stub(:[]).with(:record) { record }
14
18
  registry.stub(:[]).with(:change_pool) { change_pool }
15
- }
19
+ end
16
20
 
17
- describe "#scan" do
21
+ describe '#scan' do
18
22
  let(:dir_path) { path.join('dir') }
19
23
  let(:file_path) { dir_path.join('file.rb') }
20
24
  let(:other_file_path) { dir_path.join('other_file.rb') }
@@ -22,129 +26,182 @@ describe Listen::Directory do
22
26
  let(:other_inside_dir_path) { dir_path.join('other_inside_dir') }
23
27
  let(:dir) { Listen::Directory.new(listener, dir_path, options) }
24
28
 
25
- context "with recursive off" do
29
+ context 'with recursive off' do
26
30
  let(:options) { { recursive: false } }
27
31
 
28
- context "file & inside_dir paths present in record" do
29
- let(:record_dir_entries) { {
30
- 'file.rb' => { type: 'File' },
31
- 'inside_dir' => { type: 'Dir' } } }
32
- before {
33
- record.stub_chain(:future, :dir_entries) { double(value: record_dir_entries) }
32
+ context 'file & inside_dir paths present in record' do
33
+ let(:record_dir_entries) do
34
+ {
35
+ 'file.rb' => { type: 'File' },
36
+ 'inside_dir' => { type: 'Dir' }
37
+ }
38
+ end
39
+
40
+ before do
41
+ record.stub_chain(:future, :dir_entries) do
42
+ double(value: record_dir_entries)
43
+ end
44
+
34
45
  change_pool_async.stub(:change)
35
- }
46
+ end
36
47
 
37
- context "empty dir" do
38
- around { |example| mkdir dir_path; example.run }
48
+ context 'empty dir' do
49
+ around do |example|
50
+ mkdir dir_path
51
+ example.run
52
+ end
39
53
 
40
- it "sets record dir path" do
41
- expect(record.async).to receive(:set_path).with(dir_path, type: 'Dir')
54
+ it 'sets record dir path' do
55
+ expect(record.async).to receive(:set_path).
56
+ with(dir_path, type: 'Dir')
42
57
  dir.scan
43
58
  end
44
59
 
45
60
  it "calls change for file path and dir that doesn't exist" do
46
- expect(change_pool_async).to receive(:change).with(file_path, type: 'File', recursive: false)
47
- expect(change_pool_async).to receive(:change).with(inside_dir_path, type: 'Dir', recursive: false)
61
+ expect(change_pool_async).to receive(:change).
62
+ with(file_path, type: 'File', recursive: false)
63
+
64
+ expect(change_pool_async).to receive(:change).
65
+ with(inside_dir_path, type: 'Dir', recursive: false)
66
+
48
67
  dir.scan
49
68
  end
50
69
  end
51
70
 
52
- context "other file path present in dir" do
53
- around { |example|
54
- mkdir dir_path;
55
- touch other_file_path;
56
- example.run }
71
+ context 'other file path present in dir' do
72
+ around do |example|
73
+ mkdir dir_path
74
+ touch other_file_path
75
+ example.run
76
+ end
77
+
78
+ it 'notices file & other_file and no longer existing dir' do
79
+ expect(change_pool_async).to receive(:change).
80
+ with(file_path, type: 'File', recursive: false)
81
+
82
+ expect(change_pool_async).to receive(:change).
83
+ with(other_file_path, type: 'File', recursive: false)
84
+
85
+ expect(change_pool_async).to receive(:change).
86
+ with(inside_dir_path, type: 'Dir', recursive: false)
57
87
 
58
- it "calls change for file & other_file paths and dir that doesn't exist" do
59
- expect(change_pool_async).to receive(:change).with(file_path, type: 'File', recursive: false)
60
- expect(change_pool_async).to receive(:change).with(other_file_path, type: 'File', recursive: false)
61
- expect(change_pool_async).to receive(:change).with(inside_dir_path, type: 'Dir', recursive: false)
62
88
  dir.scan
63
89
  end
64
90
  end
65
91
  end
66
92
 
67
- context "dir paths not present in record" do
68
- before { record.stub_chain(:future, :dir_entries) { double(value: {}) } }
93
+ context 'dir paths not present in record' do
94
+ before do
95
+ record.stub_chain(:future, :dir_entries) { double(value: {}) }
96
+ end
69
97
 
70
- context "non-existing dir path" do
71
- it "calls change only for file path" do
98
+ context 'non-existing dir path' do
99
+ it 'calls change only for file path' do
72
100
  expect(change_pool_async).to_not receive(:change)
73
101
  dir.scan
74
102
  end
75
103
 
76
- it "unsets record dir path" do
104
+ it 'unsets record dir path' do
77
105
  expect(record.async).to receive(:unset_path).with(dir_path)
78
106
  dir.scan
79
107
  end
80
108
  end
81
109
 
82
- context "other file path present in dir" do
83
- around { |example|
84
- mkdir dir_path;
85
- touch file_path;
86
- example.run }
110
+ context 'other file path present in dir' do
111
+ around do |example|
112
+ mkdir dir_path
113
+ touch file_path
114
+ example.run
115
+ end
116
+
117
+ it 'calls change for file & other_file paths' do
118
+ expect(change_pool_async).to receive(:change).
119
+ with(file_path, type: 'File', recursive: false)
120
+
121
+ expect(change_pool_async).to_not receive(:change).
122
+ with(other_file_path, type: 'File', recursive: false)
123
+
124
+ expect(change_pool_async).to_not receive(:change).
125
+ with(inside_dir_path, type: 'Dir', recursive: false)
87
126
 
88
- it "calls change for file & other_file paths" do
89
- expect(change_pool_async).to receive(:change).with(file_path, type: 'File', recursive: false)
90
- expect(change_pool_async).to_not receive(:change).with(other_file_path, type: 'File', recursive: false)
91
- expect(change_pool_async).to_not receive(:change).with(inside_dir_path, type: 'Dir', recursive: false)
92
127
  dir.scan
93
128
  end
94
129
  end
95
130
  end
96
131
  end
97
132
 
98
- context "with recursive on" do
133
+ context 'with recursive on' do
99
134
  let(:options) { { recursive: true } }
100
135
 
101
- context "file & inside_dir paths present in record" do
102
- let(:record_dir_entries) { {
136
+ context 'file & inside_dir paths present in record' do
137
+ let(:record_dir_entries) do {
103
138
  'file.rb' => { type: 'File' },
104
- 'inside_dir' => { type: 'Dir' } } }
105
- before { record.stub_chain(:future, :dir_entries) { double(value: record_dir_entries) } }
139
+ 'inside_dir' => { type: 'Dir' } }
140
+ end
141
+
142
+ before do
143
+ record.stub_chain(:future, :dir_entries) do
144
+ double(value: record_dir_entries)
145
+ end
146
+ end
147
+
148
+ context 'empty dir' do
149
+ it 'calls change for file & inside_dir path' do
150
+ expect(change_pool_async).to receive(:change).
151
+ with(file_path, type: 'File', recursive: true)
152
+
153
+ expect(change_pool_async).to receive(:change).
154
+ with(inside_dir_path, type: 'Dir', recursive: true)
106
155
 
107
- context "empty dir" do
108
- it "calls change for file & inside_dir path" do
109
- expect(change_pool_async).to receive(:change).with(file_path, type: 'File', recursive: true)
110
- expect(change_pool_async).to receive(:change).with(inside_dir_path, type: 'Dir', recursive: true)
111
156
  dir.scan
112
157
  end
113
158
  end
114
159
 
115
- context "other inside_dir path present in dir" do
116
- around { |example|
117
- mkdir dir_path;
118
- mkdir other_inside_dir_path;
119
- example.run }
160
+ context 'other inside_dir path present in dir' do
161
+ around do |example|
162
+ mkdir dir_path
163
+ mkdir other_inside_dir_path
164
+ example.run
165
+ end
166
+
167
+ it 'calls change for file, other_file & inside_dir paths' do
168
+ expect(change_pool_async).to receive(:change).
169
+ with(file_path, type: 'File', recursive: true)
170
+
171
+ expect(change_pool_async).to receive(:change).
172
+ with(inside_dir_path, type: 'Dir', recursive: true)
173
+
174
+ expect(change_pool_async).to receive(:change).
175
+ with(other_inside_dir_path, type: 'Dir', recursive: true)
120
176
 
121
- it "calls change for file, other_file & inside_dir paths" do
122
- expect(change_pool_async).to receive(:change).with(file_path, type: 'File', recursive: true)
123
- expect(change_pool_async).to receive(:change).with(inside_dir_path, type: 'Dir', recursive: true)
124
- expect(change_pool_async).to receive(:change).with(other_inside_dir_path, type: 'Dir', recursive: true)
125
177
  dir.scan
126
178
  end
127
179
  end
128
180
  end
129
181
 
130
- context "dir paths not present in record" do
131
- before { record.stub_chain(:future, :dir_entries) { double(value: {}) } }
182
+ context 'dir paths not present in record' do
183
+ before do
184
+ record.stub_chain(:future, :dir_entries) { double(value: {}) }
185
+ end
132
186
 
133
- context "non-existing dir path" do
134
- it "calls change only for file path" do
187
+ context 'non-existing dir path' do
188
+ it 'calls change only for file path' do
135
189
  expect(change_pool_async).to_not receive(:change)
136
190
  dir.scan
137
191
  end
138
192
  end
139
193
 
140
- context "other file path present in dir" do
141
- around { |example|
142
- mkdir dir_path;
143
- mkdir other_inside_dir_path;
144
- example.run }
194
+ context 'other file path present in dir' do
195
+ around do |example|
196
+ mkdir dir_path
197
+ mkdir other_inside_dir_path
198
+ example.run
199
+ end
200
+
201
+ it 'calls change for file & other_file paths' do
202
+ expect(change_pool_async).to receive(:change).
203
+ with(other_inside_dir_path, type: 'Dir', recursive: true)
145
204
 
146
- it "calls change for file & other_file paths" do
147
- expect(change_pool_async).to receive(:change).with(other_inside_dir_path, type: 'Dir', recursive: true)
148
205
  dir.scan
149
206
  end
150
207
  end