Sha256: 51510200d8c8e55dc6a81c1b20cc992fff511f956bb7de82838437fa9ba782be

Contents?: true

Size: 1.62 KB

Versions: 21

Compression:

Stored size: 1.62 KB

Contents

require 'logstash-logger'

describe LogStashLogger::Device::Connectable do
  include_context 'device'

  let(:io) { double("IO") }

  subject { udp_device }

  describe "#reconnect" do
    context "with active IO connection" do
      before do
        subject.instance_variable_set(:@io, io)
      end

      it "closes the connection" do
        expect(io).to receive(:close).once
        subject.reconnect
      end
    end

    context "with no active IO connection" do
      before do
        subject.instance_variable_set(:@io, nil)
      end

      it "does nothing" do
        expect(io).to_not receive(:close)
        subject.reconnect
      end
    end
  end

  describe "#with_connection" do
    context "on exception" do
      before do
        allow(subject).to receive(:connected?) { raise(StandardError) }
        allow(subject).to receive(:warn)
      end

      context "with active IO connection" do
        before do
          subject.instance_variable_set(:@io, io)
        end

        it "closes the connection" do
          expect(io).to receive(:close).once

          expect {
            subject.with_connection do |connection|
              connection
            end
          }.to raise_error(StandardError)
        end
      end

      context "with no active IO connection" do
        before do
          subject.instance_variable_set(:@io, nil)
        end

        it "does nothing" do
          expect(io).to_not receive(:close)

          expect {
            subject.with_connection do |connection|
              connection
            end
          }.to raise_error(StandardError)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
logstash-logger-p-0.26.1 spec/device/connectable_spec.rb
logstash-logger-yajl-0.27.0 spec/device/connectable_spec.rb
logstash-logger-0.26.1 spec/device/connectable_spec.rb
logstash-logger-0.26.0 spec/device/connectable_spec.rb
logstash-logger-0.25.1 spec/device/connectable_spec.rb
logstash-logger-0.25.0 spec/device/connectable_spec.rb
logstash-logger-0.24.1 spec/device/connectable_spec.rb
logstash-logger-0.24.0 spec/device/connectable_spec.rb
logstash-logger-0.23.0 spec/device/connectable_spec.rb
logstash-logger-0.22.1 spec/device/connectable_spec.rb
logstash-logger-0.22.0 spec/device/connectable_spec.rb
logstash-logger-0.21.0 spec/device/connectable_spec.rb
logstash-logger-0.20.1 spec/device/connectable_spec.rb
logstash-logger-0.20.0 spec/device/connectable_spec.rb
logstash-logger-0.19.2 spec/device/connectable_spec.rb
logstash-logger-0.19.1 spec/device/connectable_spec.rb
logstash-logger-0.19.0 spec/device/connectable_spec.rb
logstash-logger-0.18.1 spec/device/connectable_spec.rb
logstash-logger-0.18.0 spec/device/connectable_spec.rb
logstash-logger-0.17.0 spec/device/connectable_spec.rb