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

allow stopping when not fully initialized #383

Merged
merged 3 commits into from
Apr 30, 2016
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
5 changes: 3 additions & 2 deletions lib/listen/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

module Listen
class Listener
# TODO: move the state machine's methods private
include Listen::FSM

# Initializes the directories listener.
Expand Down Expand Up @@ -63,11 +64,11 @@ def initialize(*dirs, &block)

state :initializing, to: :backend_started

state :backend_started, to: [:frontend_ready] do
state :backend_started, to: [:frontend_ready, :stopped] do
backend.start
end

state :frontend_ready, to: [:processing_events] do
state :frontend_ready, to: [:processing_events, :stopped] do
processor.setup
end

Expand Down
53 changes: 35 additions & 18 deletions spec/lib/listen/listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,43 @@
allow(backend).to receive(:start)
allow(processor).to receive(:setup)
allow(processor).to receive(:resume)
subject.start
end

it 'terminates' do
allow(backend).to receive(:stop)
allow(processor).to receive(:teardown)
subject.stop
context 'when fully started' do
before do
subject.start
end

it 'terminates' do
allow(backend).to receive(:stop)
allow(processor).to receive(:teardown)
subject.stop
end
end

context 'when frontend is ready' do
before do
subject.transition :backend_started
subject.transition :frontend_ready
end

it 'terminates' do
allow(backend).to receive(:stop)
allow(processor).to receive(:teardown)
subject.stop
end
end

context 'when only backend is already started' do
before do
subject.transition :backend_started
end

it 'terminates' do
allow(backend).to receive(:stop)
allow(processor).to receive(:teardown)
subject.stop
end
end
end

Expand Down Expand Up @@ -307,17 +337,4 @@
end
end
end

describe 'processing changes' do
before do
allow(backend).to receive(:start)
end
end

context 'when listener is stopped' do
before do
subject.stop
allow(silencer).to receive(:silenced?) { true }
end
end
end