Sha256: 187e051ac292153b9af498bdc1cf938785b78d693f8d93bea48c56595732a6f3

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'

require 'lhm/throttler'

describe Lhm::Throttler do
  include UnitHelper

  before :each do
    @mock = Class.new do
      extend Lhm::Throttler
    end
  end

  describe "#setup_throttler" do
    describe "when passing a key" do
      before do
        @mock.setup_throttler(:time_throttler, :delay => 2)
      end

      it "instantiates the time throttle" do
        @mock.throttler.class.must_equal Lhm::Throttler::Time
      end

      it "returns 2 seconds as time" do
        @mock.throttler.timeout_seconds.must_equal 2
      end
    end

    describe "when passing an instance" do

      before do
        @instance = Class.new(Lhm::Throttler::Time) do
          def timeout_seconds
            0
          end
        end.new

        @mock.setup_throttler(@instance)
      end

      it "returns the instace given" do
        @mock.throttler.must_equal @instance
      end

      it "returns 0 seconds as time" do
        @mock.throttler.timeout_seconds.must_equal 0
      end
    end

    describe "when passing a class" do

      before do
        @klass = Class.new(Lhm::Throttler::Time)
        @mock.setup_throttler(@klass)
      end

      it "has the same class as given" do
        @mock.throttler.class.must_equal @klass
      end
    end
  end

  describe "#throttler" do

    it "returns the default Time based" do
      @mock.throttler.class.must_equal Lhm::Throttler::Time
    end

    it "should default to 100 milliseconds" do
      @mock.throttler.timeout_seconds.must_equal 0.1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lhm-2.1.0 spec/unit/throttler_spec.rb