Skip to content

Commit bcda210

Browse files
authored
Merge pull request #692 from bashly-framework/fix/watcher-interrupt
Fix filewatcher interrupt
2 parents 388fff5 + db07feb commit bcda210

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/bashly/watch.rb

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

49+
def wait
50+
sleep
51+
rescue ::Interrupt => e
52+
raise Bashly::Interrupt, cause: e
53+
end
54+
4955
def listen = Listen
50-
def wait = sleep
5156
end
5257
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)