diff --git a/lib/listen/adapter/base.rb b/lib/listen/adapter/base.rb index 7819810a..2f59d9b3 100644 --- a/lib/listen/adapter/base.rb +++ b/lib/listen/adapter/base.rb @@ -85,12 +85,19 @@ def start end end + def stop + _stop + end + def self.usable? const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os'] end private + def _stop + end + def _timed(title) start = Time.now.to_f yield diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index 8ac47ec9..54564d5d 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -97,6 +97,10 @@ def _change(event_flags) def _dir_event?(event) event.flags.include?(:isdir) end + + def _stop + @worker.close + end end end end diff --git a/lib/listen/backend.rb b/lib/listen/backend.rb index a3e809b6..21125407 100644 --- a/lib/listen/backend.rb +++ b/lib/listen/backend.rb @@ -27,7 +27,7 @@ def start end def stop - # TODO: does nothing + adapter.stop end def min_delay_between_events diff --git a/spec/lib/listen/adapter/linux_spec.rb b/spec/lib/listen/adapter/linux_spec.rb index 80b6f473..148c6849 100644 --- a/spec/lib/listen/adapter/linux_spec.rb +++ b/spec/lib/listen/adapter/linux_spec.rb @@ -124,5 +124,32 @@ end end end + + describe '#stop' do + let(:fake_worker) { double(:fake_worker, close: true) } + let(:directories) { [dir1] } + let(:adapter_options) { { events: [:recursive, :close_write] } } + + before do + events = [:recursive, :close_write] + allow(fake_worker).to receive(:watch).with('/foo/dir1', *events) + + fake_notifier = double(:fake_notifier, new: fake_worker) + stub_const('INotify::Notifier', fake_notifier) + + allow(config).to receive(:directories).and_return(directories) + allow(config).to receive(:adapter_options).and_return(adapter_options) + allow(config).to receive(:queue).and_return(queue) + allow(config).to receive(:silencer).and_return(silencer) + + allow(subject).to receive(:require).with('rb-inotify') + subject.configure + end + + it 'stops the worker' do + expect(fake_worker).to receive(:close) + subject.stop + end + end end end diff --git a/spec/lib/listen/backend_spec.rb b/spec/lib/listen/backend_spec.rb index a41bfb66..3c0f82b9 100644 --- a/spec/lib/listen/backend_spec.rb +++ b/spec/lib/listen/backend_spec.rb @@ -73,7 +73,7 @@ describe '#stop' do it 'stops the adapter' do - # TODO: does nothing for now + expect(adapter).to receive(:stop) subject.stop end end