Sha256: e327ec24b40e6a6a56abe5562d3edba095c0aa4c7ed112416aa39e91d01ec1fb

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

module RSpec
  module Benchmark
    module IterationMatcher
      # Implements the `perform_at_least` matcher
      #
      # @api private
      class Matcher
        def initialize(iterations, options = {})
          @iterations = iterations
        end

        # Indicates this matcher matches against a block
        #
        # @return [True]
        #
        # @api private
        def supports_block_expectations?
          true
        end

        # @return [Boolean]
        #
        # @api private
        def matches?(block)
          @bench = ::Benchmark::Perf::Iteration.new
          @average, @stddev, _ = @bench.run(&block)
          @iterations <= (@average + 3 * @stddev)
        end

        def ips
          self
        end

        def failure_message
          "expected block to #{description}, but #{positive_failure_reason}"
        end

        def failure_message_when_negated
          "expected block not to #{description}, but #{negative_failure_reason}"
        end

        def description
          "perform at least #{@iterations} i/s"
        end

        def actual
          "%d (± %d%%) i/s" % [@average, (@stddev / @average.to_f) * 100]
        end

        def positive_failure_reason
          "performed only #{actual}"
        end

        def negative_failure_reason
          "performed #{actual}"
        end
      end
    end # IterationMatcher
  end # Benchmark
end # RSpec

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-benchmark-0.2.0 lib/rspec/benchmark/iteration_matcher.rb
rspec-benchmark-0.1.0 lib/rspec/benchmark/iteration_matcher.rb