From ff9c143c36f327942a8a12af216e5c609e33cd4e Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Sat, 20 Mar 2021 17:23:05 -0700 Subject: [PATCH] issue #533: subject.stop so thread cannot keep running and lead to raise_expired_test_double_error --- spec/lib/listen/adapter/linux_spec.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/spec/lib/listen/adapter/linux_spec.rb b/spec/lib/listen/adapter/linux_spec.rb index d87b65ff..5fe30fd6 100644 --- a/spec/lib/listen/adapter/linux_spec.rb +++ b/spec/lib/listen/adapter/linux_spec.rb @@ -12,9 +12,6 @@ end if linux? - before(:all) do - require 'rb-inotify' - end let(:dir1) { Pathname.new("/foo/dir1") } let(:config) { instance_double(Listen::Adapter::Config, "config") } @@ -26,6 +23,15 @@ # TODO: fix other adapters too! subject { described_class.new(config) } + before(:all) do + require 'rb-inotify' + allow(queue).to receive(:close) + end + + after do + subject.stop + end + describe 'watch events' do let(:directories) { [Pathname.pwd] } let(:adapter_options) { {} } @@ -40,6 +46,11 @@ allow(config).to receive(:adapter_options).and_return(adapter_options) allow(config).to receive(:queue).and_return(queue) allow(config).to receive(:silencer).and_return(silencer) + allow(fake_worker).to receive(:close) + end + + after do + subject.stop end it 'starts by calling watch with default events' do @@ -55,6 +66,7 @@ before do fake_worker = double(:fake_worker_for_inotify_limit_message) allow(fake_worker).to receive(:watch).and_raise(Errno::ENOSPC) + allow(fake_worker).to receive(:close) fake_notifier = double(:fake_notifier, new: fake_worker) stub_const('INotify::Notifier', fake_notifier) @@ -78,6 +90,7 @@ fake_worker = double(:fake_worker_for_callback) events = [:recursive, :close_write] allow(fake_worker).to receive(:watch).with('/foo/dir1', *events) + allow(fake_worker).to receive(:close) fake_notifier = double(:fake_notifier, new: fake_worker) stub_const('INotify::Notifier', fake_notifier) @@ -160,7 +173,6 @@ stub_const('INotify::Notifier', fake_notifier) allow(config).to receive(:queue).and_return(queue) - allow(queue).to receive(:close) allow(config).to receive(:silencer).and_return(silencer) allow(subject).to receive(:require).with('rb-inotify') @@ -168,7 +180,6 @@ end it 'stops the worker' do - expect(fake_worker).to receive(:close) subject.stop end end