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,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'listen/tcp/broadcaster'
4
-
5
- describe Listen::TCP::Broadcaster do
6
-
7
- let(:host) { '10.0.0.2' }
8
- let(:port) { 4000 }
9
-
10
- subject { described_class.new(host, port) }
11
-
12
- let(:server) do
13
- instance_double(described_class::TCPServer, close: true, accept: nil)
14
- end
15
-
16
- let(:socket) do
17
- instance_double(described_class::TCPSocket, close: true, write: true)
18
- end
19
-
20
- let(:socket2) do
21
- instance_double(described_class::TCPSocket, close: true, write: true)
22
- end
23
-
24
- let(:payload) { Listen::TCP::Message.new.payload }
25
-
26
- before do
27
- expect(described_class::TCPServer).to receive(:new).
28
- with(host, port).and_return server
29
- allow(server).to receive(:accept).and_raise('stub called')
30
- end
31
-
32
- after do
33
- subject.terminate
34
- end
35
-
36
- describe '#start' do
37
- it 'invokes run loop asynchronously' do
38
- expect_any_instance_of(described_class).to receive(:run)
39
- subject.start
40
- end
41
- end
42
-
43
- describe '#finalize' do
44
- before { allow(server).to receive(:accept).and_return nil }
45
-
46
- it 'closes server' do
47
- expect(server).to receive(:close)
48
- subject.finalize
49
- end
50
- end
51
-
52
- describe '#broadcast' do
53
- context 'with active socket' do
54
- before { allow(server).to receive(:accept).and_return socket, nil }
55
-
56
- it 'should broadcast payload' do
57
- expect(socket).to receive(:write).with(payload)
58
- subject.run
59
- subject.broadcast payload
60
- end
61
-
62
- it 'should keep socket' do
63
- expect(socket).to receive(:write).twice.with(payload)
64
- subject.run
65
- 2.times { subject.broadcast payload }
66
- end
67
-
68
- context 'with IOError' do
69
- it 'should remove socket from list' do
70
- allow(socket).to receive(:write).once.and_raise IOError
71
- subject.run
72
- 2.times { subject.broadcast payload }
73
- end
74
- end
75
-
76
- context 'when reset by peer' do
77
- it 'should remove socket from list' do
78
- allow(socket).to receive(:write).once.and_raise Errno::ECONNRESET
79
- subject.run
80
- 2.times { subject.broadcast payload }
81
- end
82
- end
83
-
84
- context 'when broken pipe' do
85
- it 'should remove socket from list' do
86
- allow(socket).to receive(:write).once.and_raise Errno::EPIPE
87
- subject.run
88
- 2.times { subject.broadcast payload }
89
- end
90
- end
91
-
92
- context 'with another active socket' do
93
- before do
94
- allow(server).to receive(:accept).and_return socket, socket2, nil
95
- end
96
-
97
- it 'should broadcast payload to both' do
98
- expect(socket).to receive(:write).with(payload)
99
- expect(socket2).to receive(:write).with(payload)
100
- subject.run
101
- subject.broadcast payload
102
- end
103
-
104
- context 'with a failure in first socket' do
105
- before do
106
- allow(socket).to receive(:write).once.and_raise Errno::EPIPE
107
- end
108
-
109
- it 'should still broadcast to remaining socket' do
110
- expect(socket2).to receive(:write).with(payload)
111
- subject.run
112
- subject.broadcast payload
113
- end
114
-
115
- it 'should broadcast to only remaining socket' do
116
- expect(socket2).to receive(:write).twice.with(payload)
117
- subject.run
118
- 2.times { subject.broadcast payload }
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'listen/tcp/message'
4
- require 'listen/tcp/broadcaster'
5
-
6
- describe Listen::Listener do
7
-
8
- let(:host) { '10.0.0.2' }
9
- let(:port) { 4000 }
10
-
11
- subject { described_class.new("#{host}:#{port}", :recipient, options) }
12
- let(:options) { {} }
13
- let(:registry) { instance_double(Celluloid::Registry, :[]= => true) }
14
-
15
- let(:supervisor) do
16
- instance_double(Celluloid::SupervisionGroup, add: true, pool: true)
17
- end
18
-
19
- let(:record) { instance_double(Listen::Record, terminate: true, build: true) }
20
- let(:silencer) { instance_double(Listen::Silencer, configure: nil) }
21
- let(:adapter) { instance_double(Listen::Adapter::Base) }
22
- let(:async) { instance_double(Listen::TCP::Broadcaster, broadcast: true) }
23
- let(:broadcaster) { instance_double(Listen::TCP::Broadcaster, async: async) }
24
- let(:change_pool) { instance_double(Listen::Change, terminate: true) }
25
- let(:change_pool_async) { instance_double('ChangePoolAsync') }
26
- before do
27
- allow(Celluloid::Registry).to receive(:new) { registry }
28
- allow(Celluloid::SupervisionGroup).to receive(:run!) { supervisor }
29
- allow(registry).to receive(:[]).with(:adapter) { adapter }
30
- allow(registry).to receive(:[]).with(:record) { record }
31
- allow(registry).to receive(:[]).with(:change_pool) { change_pool }
32
- allow(registry).to receive(:[]).with(:broadcaster) { broadcaster }
33
-
34
- allow(Listen::Silencer).to receive(:new) { silencer }
35
- end
36
-
37
- describe '#initialize' do
38
- it 'raises on omitted target' do
39
- expect do
40
- described_class.new(nil, :recipient)
41
- end.to raise_error ArgumentError
42
- end
43
- end
44
-
45
- context 'when broadcaster' do
46
- subject { described_class.new(port, :broadcaster) }
47
-
48
- it 'does not force TCP adapter through options' do
49
- expect(subject.options).not_to include(force_tcp: true)
50
- end
51
-
52
- describe '#start' do
53
- before do
54
- allow(subject).to receive(:_start_adapter)
55
- allow(broadcaster).to receive(:start)
56
- end
57
-
58
- it 'registers broadcaster' do
59
- expect(supervisor).to receive(:add).
60
- with(Listen::TCP::Broadcaster, as: :broadcaster, args: [nil, port])
61
- subject.start
62
- end
63
-
64
- it 'starts broadcaster' do
65
- expect(broadcaster).to receive(:start)
66
- subject.start
67
- end
68
- end
69
-
70
- describe 'queue' do
71
- before do
72
- allow(broadcaster).to receive(:async).and_return async
73
- end
74
-
75
- context 'when stopped' do
76
- it 'honours stopped state and does nothing' do
77
- allow(subject).to receive(:supervisor) do
78
- instance_double(Celluloid::SupervisionGroup, terminate: true)
79
- end
80
-
81
- subject.stop
82
- subject.queue(:file, :modified, Pathname.pwd, 'foo')
83
- expect(broadcaster).not_to receive(:async)
84
- end
85
- end
86
-
87
- let(:dir) { Pathname.pwd }
88
-
89
- it 'broadcasts changes asynchronously' do
90
- message = Listen::TCP::Message.new(:file, :modified, dir, 'foo', {})
91
- expect(async).to receive(:broadcast).with message.payload
92
- subject.queue(:file, :modified, Pathname.pwd, 'foo')
93
- end
94
- end
95
- end
96
-
97
- context 'when recipient' do
98
- subject { described_class.new(port, :recipient) }
99
-
100
- it 'forces TCP adapter through options' do
101
- expect(subject.options).to include(force_tcp: true)
102
- end
103
- end
104
- end
@@ -1,138 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Listen::TCP::Message do
6
-
7
- let(:object) { [1, 2, { 'foo' => 'bar' }] }
8
- let(:body) { '[1,2,{"foo":"bar"}]' }
9
- let(:size) { 19 }
10
- let(:payload) { "\x00\x00\x00\x13[1,2,{\"foo\":\"bar\"}]" }
11
-
12
- describe '#initialize' do
13
- it 'initializes with an object' do
14
- message = described_class.new(1, 2, 3)
15
- expect(message.object).to eq [1, 2, 3]
16
- end
17
- end
18
-
19
- describe '#object=' do
20
- subject do
21
- described_class.new(object).tap do |message|
22
- message.object = object
23
- end
24
- end
25
-
26
- describe '#object' do
27
- subject { super().object }
28
- it { is_expected.to be object }
29
- end
30
-
31
- describe '#body' do
32
- subject { super().body }
33
- it { is_expected.to eq body }
34
- end
35
-
36
- describe '#size' do
37
- subject { super().size }
38
- it { is_expected.to eq size }
39
- end
40
-
41
- describe '#payload' do
42
- subject { super().payload }
43
- it { is_expected.to eq payload }
44
- end
45
- end
46
-
47
- describe '#payload=' do
48
- subject do
49
- described_class.new(object).tap do |message|
50
- message.payload = payload
51
- end
52
- end
53
-
54
- describe '#object' do
55
- subject { super().object }
56
- it { is_expected.to eq object }
57
- end
58
-
59
- describe '#body' do
60
- subject { super().body }
61
- it { is_expected.to eq body }
62
- end
63
-
64
- describe '#size' do
65
- subject { super().size }
66
- it { is_expected.to eq size }
67
- end
68
-
69
- describe '#payload' do
70
- subject { super().payload }
71
- it { is_expected.to be payload }
72
- end
73
- end
74
-
75
- describe '.from_buffer' do
76
-
77
- context 'when buffer is empty' do
78
- it 'returns nil and leaves buffer intact' do
79
- buffer = ''
80
- message = described_class.from_buffer buffer
81
- expect(message).to be_nil
82
- expect(buffer).to eq ''
83
- end
84
- end
85
-
86
- context 'when buffer has data' do
87
-
88
- context 'with a partial packet' do
89
- it 'returns nil and leaves remaining data intact' do
90
- buffer = payload[0..4]
91
- message = described_class.from_buffer buffer
92
- expect(message).to be_nil
93
- expect(buffer).to eq payload[0..4]
94
- end
95
- end
96
-
97
- context 'with a full packet' do
98
- it 'extracts message from buffer and depletes buffer' do
99
- buffer = payload.dup
100
- message = described_class.from_buffer buffer
101
- expect(message).to be_a described_class
102
- expect(message.object).to eq object
103
- expect(buffer).to eq ''
104
- end
105
- end
106
-
107
- context 'with a full and a partial packet' do
108
- it 'extracts message from buffer and leaves remaining data intact' do
109
- buffer = payload + payload[0..10]
110
- message = described_class.from_buffer buffer
111
- expect(message).to be_a described_class
112
- expect(message.object).to eq object
113
- expect(buffer).to eq payload[0..10]
114
- end
115
- end
116
-
117
- context 'with two full packets' do
118
- it 'extracts both messages from buffer and depletes buffer' do
119
- buffer = payload + payload
120
-
121
- message1 = described_class.from_buffer buffer
122
- expect(message1).to be_a described_class
123
- expect(message1.object).to eq object
124
-
125
- message2 = described_class.from_buffer buffer
126
- expect(message2).to be_a described_class
127
- expect(message2.object).to eq object
128
-
129
- expect(message1).not_to be message2
130
- expect(buffer).to eq ''
131
- end
132
- end
133
-
134
- end
135
-
136
- end
137
-
138
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Listen do
4
- let(:listener) { instance_double(Listen::Listener, stop: nil) }
5
-
6
- after do
7
- Listen.stop
8
- end
9
-
10
- describe '.to' do
11
- it 'initalizes listener' do
12
- expect(Listen::Listener).to receive(:new).with('/path') { listener }
13
- described_class.to('/path')
14
- end
15
-
16
- context 'when using :forward_to option' do
17
- it 'initializes TCP-listener in broadcast-mode' do
18
- expect(Listen::Listener).to receive(:new).
19
- with(4000, :broadcaster, '/path', {}) { listener }
20
- described_class.to('/path', forward_to: 4000)
21
- end
22
- end
23
- end
24
-
25
- describe '.stop' do
26
- it 'stops all listeners & Celluloid' do
27
- allow(Listen::Listener).to receive(:new).with('/path') { listener }
28
- expect(listener).to receive(:stop)
29
- described_class.to('/path')
30
- Listen.stop
31
-
32
- # TODO: running? returns internal_pool on 0.15.2
33
- # (remove after Celluloid dependency is bumped)
34
- buggy_method = if Celluloid.respond_to?(:internal_pool)
35
- Celluloid.running? == Celluloid.internal_pool
36
- else
37
- false
38
- end
39
-
40
- pool = buggy_method ? Celluloid.internal_pool : Celluloid
41
- expect(pool).to_not be_running
42
- end
43
- end
44
-
45
- describe '.on' do
46
- it 'initializes TCP-listener in recipient-mode' do
47
- expect(Listen::Listener).to receive(:new).
48
- with(4000, :recipient, '/path') { listener }
49
- described_class.on(4000, '/path')
50
- end
51
- end
52
- end
@@ -1,52 +0,0 @@
1
- require 'rubygems'
2
-
3
- require 'listen'
4
- require 'listen/tcp'
5
-
6
- require 'listen/internals/thread_pool'
7
-
8
- def ci?
9
- ENV['CI']
10
- end
11
-
12
- if ci?
13
- require 'coveralls'
14
- Coveralls.wear!
15
- end
16
-
17
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
18
-
19
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
- RSpec.configure do |config|
21
- config.order = :random
22
- config.filter_run focus: true
23
- config.run_all_when_everything_filtered = true
24
- # config.fail_fast = !ci?
25
- config.expect_with :rspec do |c|
26
- c.syntax = :expect
27
- end
28
-
29
- config.mock_with :rspec do |mocks|
30
- mocks.verify_doubled_constant_names = true
31
- mocks.verify_partial_doubles = true
32
- end
33
- end
34
-
35
- require 'rspec/retry'
36
- RSpec.configure do |config|
37
- config.default_retry_count = ci? ? 5 : 1
38
- end
39
-
40
- require 'celluloid/rspec'
41
- Thread.abort_on_exception = true
42
- Celluloid.logger.level = Logger::ERROR
43
-
44
- RSpec.configuration.before(:each) do
45
- Listen::Internals::ThreadPool.stop
46
- Celluloid.boot
47
- end
48
-
49
- RSpec.configuration.after(:each) do
50
- Celluloid.shutdown
51
- Listen::Internals::ThreadPool.stop
52
- end