Skip to content

Commit b3f84ae

Browse files
committed
- Fix filewatcher interrupt
1 parent 388fff5 commit b3f84ae

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/bashly/watch.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ def changes(modified, added, removed)
4646
{ modified:, added:, removed: }
4747
end
4848

49+
def wait
50+
sleep
51+
rescue ::Interrupt => e
52+
raise e if e.is_a?(Bashly::Interrupt)
53+
54+
raise Bashly::Interrupt, cause: e
55+
end
56+
4957
def listen = Listen
50-
def wait = sleep
5158
end
5259
end

spec/bashly/watch_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
end
5656
end
5757

58+
context 'when the watch is interrupted' do
59+
it 'stops the listener and re-raises as Bashly::Interrupt' do
60+
allow(subject).to receive(:sleep).and_raise(Interrupt)
61+
62+
expect(listener).to receive(:stop)
63+
expect { subject.on_change { |_| nil } }.to raise_error(Bashly::Interrupt)
64+
end
65+
end
66+
5867
context 'when no block is provided' do
5968
it 'raises ArgumentError' do
6069
expect { subject.on_change }.to raise_error(ArgumentError, 'block required')

0 commit comments

Comments
 (0)