Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/bashly/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/bashly/watch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down