class RSpec::Benchmark::ComplexityMatcher::Matcher
Implements the `perform`
@api public
Public Class Methods
new(fit_type, **options)
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 12 def initialize(fit_type, **options) @fit_type = fit_type @threshold = options.fetch(:threshold) { RSpec::Benchmark.configuration.fit_quality } @repeat = options.fetch(:repeat) { RSpec::Benchmark.configuration.samples } @start = 8 @limit = 8 << 10 @ratio = 8 end
Public Instance Methods
actual()
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 79 def actual @trend end
description()
click to toggle source
@api private
# File lib/rspec/benchmark/complexity_matcher.rb, line 90 def description "perform #{@fit_type}" end
failure_message()
click to toggle source
@api private
# File lib/rspec/benchmark/complexity_matcher.rb, line 95 def failure_message "expected block to #{description}, but #{failure_reason}" end
failure_message_when_negated()
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 99 def failure_message_when_negated "expected block not to #{description}, but #{failure_reason}" end
failure_reason()
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 103 def failure_reason "performed #{actual}" end
in_range(start, limit = (not_set = true))
click to toggle source
Specify range of inputs
@api public
# File lib/rspec/benchmark/complexity_matcher.rb, line 50 def in_range(start, limit = (not_set = true)) case start when Array @start, *, @limit = *start @ratio = start[1] / start[0] when Numeric @start, @limit = start, limit else raise ArgumentError, "Wrong range argument '#{start}', it expects an array or numeric start value." end self end
matcher_name()
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 32 def matcher_name "perform_#{@fit_type}" end
matches?(block)
click to toggle source
@return [Boolean]
@api private
# File lib/rspec/benchmark/complexity_matcher.rb, line 39 def matches?(block) range = ::Benchmark::Trend.range(@start, @limit, ratio: @ratio) @trend, trends = ::Benchmark::Trend.infer_trend(range, repeat: @repeat, &block) threshold = trends[@trend][:residual] @trend == @fit_type && threshold >= @threshold end
ratio(ratio)
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 69 def ratio(ratio) @ratio = ratio self end
sample(repeat)
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 74 def sample(repeat) @repeat = repeat self end
supports_block_expectations?()
click to toggle source
Indicates this matcher matches against a block
@return [True]
@api private
# File lib/rspec/benchmark/complexity_matcher.rb, line 28 def supports_block_expectations? true end
threshold(threshold)
click to toggle source
# File lib/rspec/benchmark/complexity_matcher.rb, line 64 def threshold(threshold) @threshold = threshold self end
times()
click to toggle source
No-op, syntactic sugar. @api public
# File lib/rspec/benchmark/complexity_matcher.rb, line 85 def times self end