Sha256: e8e7fc3b285bb6a1c75ca2522e8d1c025236003442463b46fe27185c4f804ccc

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::Timer do
  let(:events) { [] }

  let(:times) { [1.0, 2.0] }

  before do
    allow(Process).to receive(:clock_gettime) do |argument|
      expect(argument).to be(Process::CLOCK_MONOTONIC)

      events << :clock_gettime

      times.fetch(events.count(:clock_gettime).pred)
    end
  end

  describe '.elapsed' do
    def apply
      described_class.elapsed { events << :yield }
    end

    it 'executes events in expected sequence' do
      expect { apply }
        .to change(events, :to_a)
        .from([])
        .to(%i[clock_gettime yield clock_gettime])
    end

    it 'returns elapsed time' do
      expect(apply).to be(1.0)
    end
  end

  describe '.now' do
    def apply
      described_class.now
    end

    it 'returns current monotonic time' do
      expect(apply).to be(1.0)
      expect(apply).to be(2.0)
    end

    it 'calls expected system API' do
      expect { apply }
        .to change(events, :to_a)
        .from([])
        .to(%i[clock_gettime])
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mutant-0.9.11 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.10 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.9 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.8 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.7 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.6 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.5 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.4 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.3 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.2 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.1 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.9.0 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.8.24 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.8.23 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.8.22 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.8.21 spec/unit/mutant/clock_monotonic_spec.rb
mutant-0.8.20 spec/unit/mutant/clock_monotonic_spec.rb