Sha256: 3926a44a9f71c003dc82122f21d4ebca4edd8c387a3a55d10d29e9eea98c67a8

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require "spec_helper"

describe Timber::LogDevices::HTTP::LogTruck do
  describe ".start!" do
    it "spawns a new thread" do
      expect(Thread).to receive(:new).once
      described_class.start!
    end

    it "delivers" do
      expect(described_class).to receive(:deliver).once
      described_class.start! do |thread|
        thread.kill
      end.join
    end
  end

  describe ".deliver" do
    let(:log_pile) { Timber::LogDevices::HTTP::LogPile.get(Timber::Config.application_key) }

    it "doesn't deliver because there is nothing to deliver" do
      expect(log_pile).to_not receive(:deliver)
      described_class.deliver
    end

    context "with a log pile" do
      before(:each) do
        log_line = Timber::LogLine.new("this is a log line")
        log_pile.drop(log_line)
      end

      it "delivers once and empties the log pile" do
        expect(log_pile.size).to eq(1)
        expect_any_instance_of(described_class).to receive(:deliver!).once
        described_class.deliver
        expect(log_pile.size).to eq(0)
      end
    end
  end

  describe "#initialize" do
    let(:log_lines) { [] }
    let(:log_truck) { described_class.new(Timber::Config.application_key, log_lines) }
    subject { log_truck }

    it "should raise an exception" do
      expect { subject }.to raise_exception(Timber::LogDevices::HTTP::LogTruck::NoPayloadError)
    end

    context "with log lines" do
      let(:log_lines) { [Timber::LogLine.new("hello")] }
      its(:log_lines) { should eq(log_lines) }
    end
  end

  describe "#deliver!" do
    let(:log_lines) { [Timber::LogLine.new("hello")] }
    let(:log_truck) { described_class.new(Timber::Config.application_key, log_lines) }

    it "should delivery successfully" do
      expect_any_instance_of(Timber::LogDevices::HTTP::LogTruck::Delivery).to receive(:deliver!)
      log_truck.deliver!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 spec/timber/log_devices/http/log_truck_spec.rb