From befe13c8760cc95131d88e0fbcf9f9d7a1b0008f Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 30 Apr 2016 16:37:21 +0200 Subject: [PATCH 1/3] remove unused spec code --- spec/lib/listen/listener_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spec/lib/listen/listener_spec.rb b/spec/lib/listen/listener_spec.rb index 6e6678ad..4467b7f0 100644 --- a/spec/lib/listen/listener_spec.rb +++ b/spec/lib/listen/listener_spec.rb @@ -307,17 +307,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 From 66d607945097ae6e4228e2db8f133124c34b4543 Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 30 Apr 2016 16:37:08 +0200 Subject: [PATCH 2/3] allow stopping when not fully initialized --- lib/listen/listener.rb | 4 ++-- spec/lib/listen/listener_spec.rb | 40 ++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/listen/listener.rb b/lib/listen/listener.rb index 86c6c5e8..6acf4a63 100644 --- a/lib/listen/listener.rb +++ b/lib/listen/listener.rb @@ -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 diff --git a/spec/lib/listen/listener_spec.rb b/spec/lib/listen/listener_spec.rb index 4467b7f0..19c3543e 100644 --- a/spec/lib/listen/listener_spec.rb +++ b/spec/lib/listen/listener_spec.rb @@ -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 From 9b2d077ab369fe381ab2ad7d6e6d24be3041f4e5 Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 30 Apr 2016 16:41:58 +0200 Subject: [PATCH 3/3] add TODO --- lib/listen/listener.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/listen/listener.rb b/lib/listen/listener.rb index 6acf4a63..f4688131 100644 --- a/lib/listen/listener.rb +++ b/lib/listen/listener.rb @@ -19,6 +19,7 @@ module Listen class Listener + # TODO: move the state machine's methods private include Listen::FSM # Initializes the directories listener.