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.
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
@@ -7,86 +7,89 @@ describe Listen::Record do
7
7
  let(:path) { '/dir/path/file.rb' }
8
8
  let(:data) { { type: 'File' } }
9
9
 
10
- describe "#set_path" do
11
- it "sets path by spliting direname and basename" do
10
+ describe '#set_path' do
11
+ it 'sets path by spliting direname and basename' do
12
12
  record.set_path(path, data)
13
- expect(record.paths).to eq({ '/dir/path' => { 'file.rb' => data } })
13
+ expect(record.paths).to eq('/dir/path' => { 'file.rb' => data })
14
14
  end
15
15
 
16
- it "sets path and keeps old data not overwritten" do
16
+ it 'sets path and keeps old data not overwritten' do
17
17
  record.set_path(path, data.merge(foo: 1, bar: 2))
18
18
  record.set_path(path, data.merge(foo: 3))
19
- expect(record.paths).to eq({ '/dir/path' => { 'file.rb' => data.merge(foo: 3, bar: 2) } })
19
+ expected = { '/dir/path' => { 'file.rb' => data.merge(foo: 3, bar: 2) } }
20
+ expect(record.paths).to eq(expected)
20
21
  end
21
22
  end
22
23
 
23
- describe "#unset_path" do
24
- context "path is present" do
24
+ describe '#unset_path' do
25
+ context 'path is present' do
25
26
  before { record.set_path(path, data) }
26
27
 
27
- it "unsets path" do
28
+ it 'unsets path' do
28
29
  record.unset_path(path)
29
- expect(record.paths).to eq({ '/dir/path' => {} })
30
+ expect(record.paths).to eq('/dir/path' => {})
30
31
  end
31
32
  end
32
33
 
33
- context "path not present" do
34
- it "unsets path" do
34
+ context 'path not present' do
35
+ it 'unsets path' do
35
36
  record.unset_path(path)
36
- expect(record.paths).to eq({ '/dir/path' => {} })
37
+ expect(record.paths).to eq('/dir/path' => {})
37
38
  end
38
39
  end
39
40
  end
40
41
 
41
- describe "#file_data" do
42
- context "path is present" do
42
+ describe '#file_data' do
43
+ context 'path is present' do
43
44
  before { record.set_path(path, data) }
44
45
 
45
- it "returns file data" do
46
+ it 'returns file data' do
46
47
  expect(record.file_data(path)).to eq data
47
48
  end
48
49
  end
49
50
 
50
- context "path not present" do
51
- it "return empty hash" do
51
+ context 'path not present' do
52
+ it 'return empty hash' do
52
53
  expect(record.file_data(path)).to be_empty
53
54
  end
54
55
  end
55
56
  end
56
57
 
57
- describe "#dir_entries" do
58
- context "path is present" do
58
+ describe '#dir_entries' do
59
+ context 'path is present' do
59
60
  before { record.set_path(path, data) }
60
61
 
61
- it "returns file path" do
62
- expect(record.dir_entries('/dir/path')).to eq({ 'file.rb' => data })
62
+ it 'returns file path' do
63
+ expect(record.dir_entries('/dir/path')).to eq('file.rb' => data)
63
64
  end
64
65
  end
65
66
 
66
- context "path not present" do
67
- it "unsets path" do
67
+ context 'path not present' do
68
+ it 'unsets path' do
68
69
  expect(record.dir_entries('/dir/path')).to eq({})
69
70
  end
70
71
  end
71
72
  end
72
73
 
73
- describe "#build" do
74
+ describe '#build' do
74
75
  let(:directories) { ['dir_path'] }
75
76
  let(:change_pool) { double(Listen::Change, terminate: true) }
76
- before {
77
+ before do
77
78
  change_pool.stub(:change)
78
79
  registry.stub(:[]).with(:change_pool) { change_pool }
79
80
  listener.stub(:directories) { directories }
80
- }
81
+ end
81
82
 
82
- it "re-inits paths" do
83
+ it 're-inits paths' do
83
84
  record.set_path(path, data)
84
85
  record.build
85
86
  expect(record.file_data(path)).to be_empty
86
87
  end
87
88
 
88
- it "calls change asynchronously on all directories to build record" do
89
- expect(change_pool).to receive(:change).with('dir_path', type: 'Dir', recursive: true, silence: true)
89
+ it 'calls change asynchronously on all directories to build record' do
90
+ expect(change_pool).to receive(:change).
91
+ with('dir_path', type: 'Dir', recursive: true, silence: true)
92
+
90
93
  record.build
91
94
  end
92
95
  end
@@ -2,17 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe Listen::Silencer do
4
4
  let(:options) { {} }
5
- let(:listener) { double(Listen::Listener,
6
- directories: [Pathname.new(Dir.pwd), Pathname.new("/Users/Shared/")],
7
- options: options
8
- ) }
5
+
6
+ let(:listener) do
7
+ double(Listen::Listener,
8
+ directories: [Pathname.pwd, Pathname.new('/Users/Shared/')],
9
+ options: options
10
+ )
11
+ end
12
+
9
13
  let(:silencer) { Listen::Silencer.new(listener) }
10
14
 
11
- describe "#silenced?" do
12
- let(:pwd) { Pathname.new(Dir.pwd) }
15
+ describe '#silenced?' do
16
+ let(:pwd) { Pathname.pwd }
13
17
 
14
- context "default ignore" do
15
- Listen::Silencer::DEFAULT_IGNORED_DIRECTORIES.each do |dir|
18
+ context 'default ignore' do
19
+ hidden_dirs = %w(.git .svn .hg .rbx .bundle)
20
+ other_dirs = %w(bundle vendor/bundle log tmp vendor/ruby)
21
+ (hidden_dirs + other_dirs).each do |dir|
16
22
  describe do
17
23
  let(:path) { pwd.join(dir) }
18
24
 
@@ -20,7 +26,7 @@ describe Listen::Silencer do
20
26
  expect(silencer.silenced?(path)).to be_true
21
27
  end
22
28
 
23
- context "with a directory beginning with the same name" do
29
+ context 'with a directory beginning with the same name' do
24
30
  let(:path) { pwd.join("#{dir}foo") }
25
31
 
26
32
  it "doesn't silences default ignored directory: #{dir}foo" do
@@ -28,7 +34,7 @@ describe Listen::Silencer do
28
34
  end
29
35
  end
30
36
 
31
- context "with a directory ending with the same name" do
37
+ context 'with a directory ending with the same name' do
32
38
  let(:path) { pwd.join("foo#{dir}") }
33
39
 
34
40
  it "doesn't silences default ignored directory: foo#{dir}" do
@@ -38,10 +44,12 @@ describe Listen::Silencer do
38
44
  end
39
45
  end
40
46
 
41
- %w(.DS_Store foo.tmp foo~ foo.rbo54321.new).each do |path|
47
+ gedit_files = %w(.goutputstream-S3FBGX)
48
+ kate_files = %w(foo.rbo54321.new foo.rbB22583.new foo.rb.kate-swp)
49
+ (%w(.DS_Store foo.tmp foo~) + kate_files + gedit_files).each do |path|
42
50
  describe do
43
51
  it "by default silences files like: #{path}" do
44
- expect(silencer.silenced?(pwd.join(path))).to be_true
52
+ expect(silencer.silenced?(pwd + path)).to be_true
45
53
  end
46
54
  end
47
55
  end
@@ -49,7 +57,7 @@ describe Listen::Silencer do
49
57
  %w(foo.tmpl file.new file54321.new).each do |path|
50
58
  describe do
51
59
  it "by default does not silence files like: #{path}" do
52
- expect(silencer.silenced?(pwd.join(path))).to be_false
60
+ expect(silencer.silenced?(pwd + path)).to be_false
53
61
  end
54
62
  end
55
63
  end
@@ -58,102 +66,116 @@ describe Listen::Silencer do
58
66
  context 'with ignore options (regexp)' do
59
67
  let(:options) { { ignore: /\.pid$/ } }
60
68
 
61
- it "silences path matching custom ignore regex" do
62
- expect(silencer.silenced?(pwd.join('foo.pid'))).to be_true
69
+ it 'silences path matching custom ignore regex' do
70
+ expect(silencer.silenced?(pwd + 'foo.pid')).to be_true
63
71
  end
64
72
  end
65
73
 
66
74
  context 'with ignore options (array)' do
67
75
  let(:options) { { ignore: [%r{^foo/bar}, /\.pid$/] } }
68
76
 
69
- it "silences paths matching custom ignore regexes" do
70
- expect(silencer.silenced?(pwd.join('foo/bar/baz'))).to be_true
71
- expect(silencer.silenced?(pwd.join('foo.pid'))).to be_true
77
+ it 'silences paths matching custom ignore regexes' do
78
+ expect(silencer.silenced?(pwd + 'foo/bar/baz')).to be_true
79
+ expect(silencer.silenced?(pwd + 'foo.pid')).to be_true
72
80
  end
73
81
  end
74
82
 
75
- context "with ignore! options" do
83
+ context 'with ignore! options' do
76
84
  let(:options) { { ignore!: /\.pid$/ } }
77
85
 
78
- it "silences custom ignored directory" do
79
- expect(silencer.silenced?(pwd.join('foo.pid'))).to be_true
86
+ it 'silences custom ignored directory' do
87
+ expect(silencer.silenced?(pwd + 'foo.pid')).to be_true
80
88
  end
81
89
 
82
90
  it "doesn't silence default ignored directory" do
83
- path = pwd.join(Listen::Silencer::DEFAULT_IGNORED_DIRECTORIES.first)
84
- expect(silencer.silenced?(path)).to be_false
91
+ expect(silencer.silenced?(pwd + '.git')).to be_false
85
92
  end
86
93
  end
87
94
 
88
- context "with only options (regexp)" do
95
+ context 'with only options (regexp)' do
89
96
  let(:options) { { only: %r{foo} } }
90
97
 
91
- it "do not take only regex in account if type is Unknown" do
92
- path = pwd.join('baz')
93
- expect(silencer.silenced?(path)).to be_false
98
+ it 'do not take only regex in account if type is Unknown' do
99
+ expect(silencer.silenced?(pwd + 'baz')).to be_false
94
100
  end
95
101
 
96
- it "do not silence path matches only regex if type is File" do
97
- path = pwd.join('foo')
98
- expect(silencer.silenced?(path, 'File')).to be_false
102
+ it 'do not silence path matches only regex if type is File' do
103
+ expect(silencer.silenced?(pwd + 'foo', 'File')).to be_false
99
104
  end
100
105
 
101
- it "silences other directory" do
102
- path = pwd.join('bar')
103
- expect(silencer.silenced?(path, 'File')).to be_true
106
+ it 'silences other directory' do
107
+ expect(silencer.silenced?(pwd + 'bar', 'File')).to be_true
104
108
  end
105
109
  end
106
110
 
107
- context "with only options (array)" do
111
+ context 'with only options (array)' do
108
112
  let(:options) { { only: [%r{^foo/}, %r{\.txt$}] } }
109
113
 
110
- it "do not take only regex in account if type is Unknown" do
111
- expect(silencer.silenced?(pwd.join('baz'))).to be_false
114
+ it 'do not take only regex in account if type is Unknown' do
115
+ expect(silencer.silenced?(pwd + 'baz')).to be_false
112
116
  end
113
117
 
114
118
  it "doesn't silence good directory" do
115
- expect(silencer.silenced?(pwd.join('foo/bar.rb'), 'File')).to be_false
119
+ expect(silencer.silenced?(pwd + 'foo/bar.rb', 'File')).to be_false
116
120
  end
117
121
 
118
122
  it "doesn't silence good file" do
119
- expect(silencer.silenced?(pwd.join('bar.txt'), 'File')).to be_false
123
+ expect(silencer.silenced?(pwd + 'bar.txt', 'File')).to be_false
120
124
  end
121
125
 
122
- it "silences other directory" do
123
- expect(silencer.silenced?(pwd.join('bar/baz.rb'), 'File')).to be_true
126
+ it 'silences other directory' do
127
+ expect(silencer.silenced?(pwd + 'bar/baz.rb', 'File')).to be_true
124
128
  end
125
129
 
126
- it "silences other file" do
127
- expect(silencer.silenced?(pwd.join('bar.rb'), 'File')).to be_true
130
+ it 'silences other file' do
131
+ expect(silencer.silenced?(pwd + 'bar.rb', 'File')).to be_true
128
132
  end
129
133
  end
130
134
 
131
135
  context 'with ignore and only options' do
132
136
  let(:options) { { only: /\.pid$/, ignore: %r{^bar} } }
133
137
 
134
- it "do not take only regex in account if type is Unknown" do
135
- expect(silencer.silenced?(pwd.join('baz'))).to be_false
136
- end
138
+ context 'with Unknown type' do
139
+ context 'when not matching :only' do
140
+ context 'when not matching :ignore' do
141
+ it 'does not silence' do
142
+ expect(silencer.silenced?(pwd + 'baz')).to be_false
143
+ end
144
+ end
137
145
 
138
- it "do not take only regex in account if type is Unknown but silences if ignore regex matches path" do
139
- expect(silencer.silenced?(pwd.join('bar'))).to be_true
146
+ context 'when matching :ignore' do
147
+ it 'silences' do
148
+ expect(silencer.silenced?(pwd + 'bar')).to be_true
149
+ end
150
+ end
151
+ end
140
152
  end
141
153
 
142
- it 'silences path not matching custom only regex' do
143
- expect(silencer.silenced?(pwd.join('foo.rb'), 'File')).to be_true
144
- end
154
+ context 'with File type' do
155
+ context 'when not matching :only' do
156
+ it 'silences' do
157
+ expect(silencer.silenced?(pwd + 'foo.rb', 'File')).to be_true
158
+ end
159
+ end
145
160
 
146
- it 'silences path matching custom ignore regex' do
147
- expect(silencer.silenced?(pwd.join('bar.pid', 'File'))).to be_true
148
- end
161
+ context 'when matching :only' do
162
+ context 'when matching :ignore' do
163
+ it 'silences' do
164
+ expect(silencer.silenced?(pwd + 'bar.pid', 'File')).to be_true
165
+ end
166
+ end
149
167
 
150
- it 'do not silence path matching custom only regex and not matching custom ignore regex' do
151
- expect(silencer.silenced?(pwd.join('foo.pid', 'File'))).to be_false
168
+ context 'when not matching :ignore' do
169
+ it 'does not silence' do
170
+ expect(silencer.silenced?(pwd + 'foo.pid', 'File')).to be_false
171
+ end
172
+ end
173
+ end
152
174
  end
153
175
  end
154
176
 
155
177
  it "doesn't silence normal path" do
156
- path = pwd.join('some_dir', 'some_file.rb')
178
+ path = pwd + 'some_dir' + 'some_file.rb'
157
179
  expect(silencer.silenced?(path)).to be_false
158
180
  end
159
181
  end
@@ -6,12 +6,13 @@ describe Listen::TCP::Broadcaster do
6
6
  let(:port) { 4000 }
7
7
 
8
8
  subject { described_class.new(host, port) }
9
- let(:server) { double(described_class::TCPServer, close: true, accept: nil) }
9
+ let(:server) { double(described_class::TCPServer, close: true, accept: nil) }
10
10
  let(:socket) { double(described_class::TCPSocket, write: true) }
11
11
  let(:payload) { Listen::TCP::Message.new.payload }
12
12
 
13
13
  before do
14
- expect(described_class::TCPServer).to receive(:new).with(host, port).and_return server
14
+ expect(described_class::TCPServer).to receive(:new).
15
+ with(host, port).and_return server
15
16
  end
16
17
 
17
18
  after do
@@ -8,14 +8,18 @@ describe Listen::TCP::Listener do
8
8
  subject { described_class.new("#{host}:#{port}", :recipient, options) }
9
9
  let(:options) { {} }
10
10
  let(:registry) { double(Celluloid::Registry, :[]= => true) }
11
- let(:supervisor) { double(Celluloid::SupervisionGroup, add: true, pool: true) }
11
+
12
+ let(:supervisor) do
13
+ double(Celluloid::SupervisionGroup, add: true, pool: true)
14
+ end
15
+
12
16
  let(:record) { double(Listen::Record, terminate: true, build: true) }
13
17
  let(:silencer) { double(Listen::Silencer, terminate: true) }
14
18
  let(:adapter) { double(Listen::Adapter::Base) }
15
19
  let(:broadcaster) { double(Listen::TCP::Broadcaster) }
16
20
  let(:change_pool) { double(Listen::Change, terminate: true) }
17
21
  let(:change_pool_async) { double('ChangePoolAsync') }
18
- before {
22
+ before do
19
23
  Celluloid::Registry.stub(:new) { registry }
20
24
  Celluloid::SupervisionGroup.stub(:run!) { supervisor }
21
25
  registry.stub(:[]).with(:silencer) { silencer }
@@ -23,7 +27,7 @@ describe Listen::TCP::Listener do
23
27
  registry.stub(:[]).with(:record) { record }
24
28
  registry.stub(:[]).with(:change_pool) { change_pool }
25
29
  registry.stub(:[]).with(:broadcaster) { broadcaster }
26
- }
30
+ end
27
31
 
28
32
  describe '#initialize' do
29
33
  its(:mode) { should be :recipient }
@@ -64,7 +68,8 @@ describe Listen::TCP::Listener do
64
68
  end
65
69
 
66
70
  it 'registers broadcaster' do
67
- expect(supervisor).to receive(:add).with(Listen::TCP::Broadcaster, as: :broadcaster, args: [nil, port])
71
+ expect(supervisor).to receive(:add).
72
+ with(Listen::TCP::Broadcaster, as: :broadcaster, args: [nil, port])
68
73
  subject.start
69
74
  end
70
75
 
@@ -77,11 +82,9 @@ describe Listen::TCP::Listener do
77
82
  describe '#block' do
78
83
  let(:async) { double('TCP broadcaster async', broadcast: true) }
79
84
  let(:callback) { double(call: true) }
80
- let(:changes) { {
81
- modified: ['/foo'],
82
- added: [],
83
- removed: []
84
- }}
85
+ let(:changes) do
86
+ { modified: ['/foo'], added: [], removed: [] }
87
+ end
85
88
 
86
89
  before do
87
90
  broadcaster.stub(:async).and_return async
@@ -101,7 +104,10 @@ describe Listen::TCP::Listener do
101
104
 
102
105
  context 'when stopped' do
103
106
  it 'honours stopped state and does nothing' do
104
- allow(subject).to receive(:supervisor) { double('SupervisionGroup', terminate: true) }
107
+ allow(subject).to receive(:supervisor) do
108
+ double('SupervisionGroup', terminate: true)
109
+ end
110
+
105
111
  subject.stop
106
112
  expect(broadcaster).not_to receive(:async)
107
113
  expect(callback).not_to receive(:call)
@@ -115,7 +121,7 @@ describe Listen::TCP::Listener do
115
121
 
116
122
  it 'invokes original callback block' do
117
123
  subject.block = callback
118
- expect(callback).to receive(:call).with *changes.values
124
+ expect(callback).to receive(:call).with(*changes.values)
119
125
  end
120
126
  end
121
127
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Listen::TCP::Message do
6
6
 
7
- let(:object) { [1, 2, {'foo' => 'bar'}] }
7
+ let(:object) { [1, 2, { 'foo' => 'bar' }] }
8
8
  let(:body) { '[1,2,{"foo":"bar"}]' }
9
9
  let(:size) { 19 }
10
10
  let(:payload) { "\x00\x00\x00\x13[1,2,{\"foo\":\"bar\"}]" }