diff --git a/lib/bashly/watch.rb b/lib/bashly/watch.rb index f4b53e0c..a33ba2de 100644 --- a/lib/bashly/watch.rb +++ b/lib/bashly/watch.rb @@ -46,7 +46,12 @@ def changes(modified, added, removed) { modified:, added:, removed: } end + def wait + sleep + rescue ::Interrupt => e + raise Bashly::Interrupt, cause: e + end + def listen = Listen - def wait = sleep end end diff --git a/spec/bashly/watch_spec.rb b/spec/bashly/watch_spec.rb index 830eea15..c295e577 100644 --- a/spec/bashly/watch_spec.rb +++ b/spec/bashly/watch_spec.rb @@ -55,6 +55,15 @@ end end + context 'when the watch is interrupted' do + it 'stops the listener and re-raises as Bashly::Interrupt' do + allow(subject).to receive(:sleep).and_raise(Interrupt) + + expect(listener).to receive(:stop) + expect { subject.on_change { |_| nil } }.to raise_error(Bashly::Interrupt) + end + end + context 'when no block is provided' do it 'raises ArgumentError' do expect { subject.on_change }.to raise_error(ArgumentError, 'block required')