Skip to content

Commit

Permalink
issue #533: subject.stop so thread cannot keep running and lead to ra…
Browse files Browse the repository at this point in the history
…ise_expired_test_double_error
  • Loading branch information
ColinDKelley committed Mar 21, 2021
1 parent c24d860 commit 57224cc
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions spec/lib/listen/adapter/linux_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Listen::Adapter::Linux do
describe 'class' do
describe 'class methods' do
subject { described_class }

if linux?
Expand All @@ -12,20 +12,26 @@
end

if linux?
describe 'instance methods' do
before(:all) do
require 'rb-inotify'
end

let(:dir1) { Pathname.new("/foo/dir1") }

let(:config) { instance_double(Listen::Adapter::Config, "config") }
let(:queue) { instance_double(Queue, "queue") }
let(:queue) { instance_double(Queue, "queue", close: nil) }
let(:config) { instance_double(Listen::Adapter::Config, "config", queue: queue) }
let(:silencer) { instance_double(Listen::Silencer, "silencer") }
let(:snapshot) { instance_double(Listen::Change, "snapshot") }
let(:record) { instance_double(Listen::Record, "record") }

# TODO: fix other adapters too!
subject { described_class.new(config) }

after do
subject.stop
end

describe 'watch events' do
let(:directories) { [Pathname.pwd] }
let(:adapter_options) { {} }
Expand All @@ -38,8 +44,12 @@

allow(config).to receive(:directories).and_return(directories)
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
Expand All @@ -55,6 +65,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)
Expand All @@ -78,13 +89,13 @@
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)

allow(config).to receive(:directories).and_return(directories)
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(Listen::Record).to receive(:new).with(dir1).and_return(record)
Expand Down Expand Up @@ -159,23 +170,19 @@
fake_notifier = double(:fake_notifier, new: fake_worker)
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')
subject.configure
end

it 'stops the worker' do
expect(fake_worker).to receive(:close)
subject.stop
end
end

context 'when not even initialized' do
before do
allow(config).to receive(:queue).and_return(queue)
allow(queue).to receive(:close)
end

Expand All @@ -187,4 +194,5 @@
end
end
end
end
end

0 comments on commit 57224cc

Please sign in to comment.