Skip to content

Commit

Permalink
allow stopping when not fully initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Apr 30, 2016
1 parent 402a79e commit d0ce6c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/listen/listener.rb
Expand Up @@ -63,11 +63,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
40 changes: 35 additions & 5 deletions spec/lib/listen/listener_spec.rb
Expand Up @@ -137,13 +137,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

0 comments on commit d0ce6c6

Please sign in to comment.