Sha256: fa291a3a684bc382e482520256800ecfd67e9f62265c2f265870636cbcc9f8b9

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require "spec_helper"

describe XRayMachine::LogSubscriber do
  before { XRayMachine::LogSubscriber.reset_runtimes }
  before { XRayMachine.instance_eval{ @options = nil } }

  describe ".runtimes" do
    subject { XRayMachine::LogSubscriber.runtimes }

    it { is_expected.to be_a Hash }
    it { is_expected.to eq({}) }

    it "returns the same object all the time" do
      other_object = XRayMachine::LogSubscriber.runtimes

      is_expected.to be other_object
    end
  end

  describe "#request" do
    let(:subscriber) { XRayMachine::LogSubscriber.new }
    let(:event) { double("Event", duration: 11, payload: payload) }
    let(:payload) { {query: "some/query/data", cache: false, group: "external_api"} }

    subject { subscriber.request(event) }

    before do
      def subscriber.debug(string=nil)
        @debug ||= string
      end
    end

    it "saves the duration in the runtimes list" do
      expect{ subject }.to change{ XRayMachine::LogSubscriber.runtimes }.to({"external_api" => 11})
    end

    it "dumps the data in the debugging stream" do
      expect{ subject }.to change{ subscriber.debug }
        .to("  \e[1m\e[31mExternalApi (11.0ms)\e[0m  some/query/data")
    end

    it "marks things cached when the payload have a cache:true option" do
      payload[:cache] = true

      expect{ subject }.to change{ subscriber.debug }
      .to("  \e[1m\e[31mExternalApi CACHE (11.0ms)\e[0m  some/query/data")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
x-ray-machine-1.0.4 spec/lib/x_ray_machine/log_subscriber_spec.rb
x-ray-machine-1.0.3 spec/lib/x_ray_machine/log_subscriber_spec.rb
x-ray-machine-1.0.2 spec/lib/x_ray_machine/log_subscriber_spec.rb
x-ray-machine-1.0.1 spec/lib/x_ray_machine/log_subscriber_spec.rb