Sha256: 53cf9b9aa8d7272742b1ad1f45594d900c6a2c77eb57f2d7fec266ca5af9aa87

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe Harvestdor::Indexer::Metrics do
  it "should record successes" do
    expect { subject.success! }.to change { subject.success_count }.from(0).to(1)
  end

  it "should record errors" do
    expect { subject.error! }.to change { subject.error_count }.from(0).to(1)
  end

  describe "#total" do
    it "should be the sum of the successes and errors" do
      expect do 
        subject.error!
        subject.success!
      end.to change { subject.total }.from(0).to(2)
    end
  end

  describe "#tally" do
    it "should record a success if the block doesn't fail" do
      expect do
        subject.tally do
          #noop
        end
      end.to change { subject.success_count }.from(0).to(1)
    end
    
    it "should record an error if the block fails" do
      expect do
        subject.tally do
          raise "Broken"
        end
      end.to change { subject.error_count }.from(0).to(1)
    end

    it "should allow an error handler to be provided" do
      x = double
      expect(x).to receive(:call).with(kind_of(RuntimeError))
      subject.tally(on_error: x) do
        raise "Broken"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
harvestdor-indexer-2.1.1 spec/unit/harvestdor/indexer/metrics_spec.rb
harvestdor-indexer-2.1.0 spec/unit/harvestdor/indexer/metrics_spec.rb
harvestdor-indexer-2.0.0 spec/unit/harvestdor/indexer/metrics_spec.rb