Sha256: 78ffc05b0c405da15a67d648ec8f89f403b0452420f2f9b970e7cf586f064c80

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module Vedeu

  module Logging

    describe Timer do

      let(:described) { Vedeu::Logging::Timer }
      let(:instance)  { described.new(_message) }
      let(:_message)  { 'Testing' }
      let(:_time)     { 1219.523818 }

      before do
        Vedeu.stubs(:clock_time).returns(_time)
      end

      describe '#initialize' do
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@message').must_equal(_message) }
        it { instance.instance_variable_get('@started').must_equal(_time) }
      end

      describe '.timer' do
        it { described.must_respond_to(:timer) }
      end

      describe '#measure' do
        context 'when the block is given' do
          subject { instance.measure { :thing_to_be_measured } }

          context 'when debugging is enabled' do
            before { Vedeu.config.stubs(:debug?).returns(true) }

            it do
              Vedeu.expects(:log)
                .with(type:    :timer,
                      message: "Testing took 0.0ms.")
              subject
            end
          end

          context 'when debugging is disabled' do
            before { Vedeu.config.stubs(:debug?).returns(false) }

            it { subject.must_equal(:thing_to_be_measured) }
          end
        end

        context 'when the block is not given' do
          subject { instance.measure }

          it { proc { subject }.must_raise(Vedeu::Error::RequiresBlock) }
        end
      end

    end # Timer

  end # Logging

end # Vedeu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
vedeu-0.8.32 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.31 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.30 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.29 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.28 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.27 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.26 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.25 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.24 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.23 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.22 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.21 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.20 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.19 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.18 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.17 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.16 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.15 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.14 test/lib/vedeu/logging/timer_test.rb
vedeu-0.8.13 test/lib/vedeu/logging/timer_test.rb