Sha256: a59082dc55afd9951bf0a8e18cba5a7b1f737354fe79117727dd52cefdbb7398

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

module Benches
  module Matchers

    RSpec::Matchers.define :run do |repetitions|

      chain :time_in_less_than do |duration|
        @duration = duration
      end

      chain :times_in_less_than do |duration|
        @duration = duration
      end

      match do |actual|
        Benchmark.measure do
          repetitions.times do
            actual.call
          end
        end.utime.seconds < @duration
      end

      failure_message_for_should do |actual|
        "expected code to run in less than #{@duration.inspect}"
      end

      failure_message_for_should_not do |actual|
        "expected code not to run in less than #{@duration.inspect} seconds"
      end

      description do
        "run in less than #{@duration.inspect}"
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
benches-0.3.1 lib/benches/matchers/run.rb
benches-0.3.0 lib/benches/matchers/run.rb