Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Adapter#stop [fix #353] #359

Merged
merged 1 commit into from
Nov 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/listen/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/listen/adapter/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/listen/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def start
end

def stop
# TODO: does nothing
adapter.stop
end

def min_delay_between_events
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/listen/adapter/linux_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/lib/listen/backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down