Sha256: 87f25266978fdc9ddac963e784c556f984fe283f83b99853370c8a134da8130a

Contents?: true

Size: 1.52 KB

Versions: 20

Compression:

Stored size: 1.52 KB

Contents

require 'rails_helper'

RSpec.describe Kuroko2::MemoryConsumptionLog do
  around {|example| Timecop.freeze(Time.current) { example.run } }

  describe described_class::Interval do
    describe '#reached?' do
      let(:interval) { described_class.new(base, count) }
      let(:base) { Time.current }

      context 'count = 0 and 2 seconds since' do
        let(:count) { 0 }
        let(:now) { 2.seconds.since.to_time }
        it { expect(interval.reached?(now)).to be_truthy }
      end

      context 'count = 10 and 2 minutes since' do
        let(:count) { 10 }
        let(:now) { 2.minutes.since.to_time }
        it { expect(interval.reached?(now)).to be_truthy }
      end

      context 'count = 100 and 31 minutes since' do
        let(:count) { 100 }
        let(:now) { 31.minutes.since.to_time }
        it { expect(interval.reached?(now)).to be_truthy }
      end
    end

    describe '#next' do
      it 'returns count-up-ed Interval' do
        a = described_class.new(Time.current)
        b = a.next
        expect(b).to be_a(described_class)

        diff = b.count - a.count
        expect(diff).to eq(1)
      end
    end

    it 'behaves as certain period interval with #reached? and #next' do
      a = described_class.new(Time.current, 100)
      expect(a.reached?(29.minutes.since.to_time)).to be_falsy
      expect(a.reached?(31.minutes.since.to_time)).to be_truthy
      b = a.next
      expect(b.reached?(59.minutes.since.to_time)).to be_falsy
      expect(b.reached?(61.minutes.since.to_time)).to be_truthy
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
kuroko2-0.8.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.7.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.6.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.5.2 spec/models/memory_consumption_log_spec.rb
kuroko2-0.5.1 spec/models/memory_consumption_log_spec.rb
kuroko2-0.5.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.6 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.5 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.4 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.3 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.2 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.1 spec/models/memory_consumption_log_spec.rb
kuroko2-0.4.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.3.4 spec/models/memory_consumption_log_spec.rb
kuroko2-0.3.3 spec/models/memory_consumption_log_spec.rb
kuroko2-0.3.2 spec/models/memory_consumption_log_spec.rb
kuroko2-0.3.1 spec/models/memory_consumption_log_spec.rb
kuroko2-0.3.0 spec/models/memory_consumption_log_spec.rb
kuroko2-0.2.3 spec/models/memory_consumption_log_spec.rb
kuroko2-0.2.2 spec/models/memory_consumption_log_spec.rb