Sha256: 915ec0c2e7280d2a465124c287cb1968377f1cb29c015a4d5815745b242d5fc7

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true
require_relative "../spec_helper"

require_relative "../../lib/ultravisor"

describe Ultravisor do
  let(:args) { {} }
  let(:ultravisor) { Ultravisor.new(**args) }
  let(:mock_child) { instance_double(Ultravisor::Child) }

  describe "#remove_child" do
    before(:each) do
      ultravisor.instance_variable_set(:@children, [[:lamb, mock_child]])
    end

    context "when the ultravisor isn't running" do
      it "removes the child from the list of children" do
        ultravisor.remove_child(:lamb)

        expect(ultravisor[:lamb]).to be(nil)
      end

      it "doesn't explode if asked to remove a child that doesn't exist" do
        expect { ultravisor.remove_child(:no_such_child) }.to_not raise_error
      end
    end

    context "while the ultravisor is running" do
      let(:mock_thread) { instance_double(Thread) }

      before(:each) do
        allow(mock_child).to receive(:shutdown)
        ultravisor.instance_variable_set(:@running_thread, mock_thread)
      end

      it "shuts down the child" do
        expect(mock_child).to receive(:shutdown)

        ultravisor.remove_child(:lamb)
      end

      it "removes the child from the list of children" do
        ultravisor.remove_child(:lamb)

        expect(ultravisor[:lamb]).to be(nil)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-2.1.0 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-1.0.5 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-2.0.2 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-2.0.1 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-2.0.0 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-1.0.4 ultravisor/spec/ultravisor/remove_child_spec.rb
service_skeleton-0.0.0.1.ENOTAG ultravisor/spec/ultravisor/remove_child_spec.rb