Class: RSpec::Benchmark::ComplexityMatcher::Matcher
- Inherits:
-
Object
- Object
- RSpec::Benchmark::ComplexityMatcher::Matcher
- Defined in:
- lib/rspec/benchmark/complexity_matcher.rb
Overview
Implements the ‘perform`
Instance Method Summary collapse
- #actual ⇒ Object
- #description ⇒ Object private
- #failure_message ⇒ Object private
- #failure_message_when_negated ⇒ Object
- #failure_reason ⇒ Object
-
#in_range(start, limit = (not_set = true)) ⇒ Object
Specify range of inputs.
-
#initialize(fit_type, **options) ⇒ Matcher
constructor
A new instance of Matcher.
- #matcher_name ⇒ Object
- #matches?(block) ⇒ Boolean private
- #ratio(ratio) ⇒ Object
- #sample(repeat) ⇒ Object
-
#supports_block_expectations? ⇒ True
private
Indicates this matcher matches against a block.
- #threshold(threshold) ⇒ Object
-
#times ⇒ Object
No-op, syntactic sugar.
Constructor Details
#initialize(fit_type, **options) ⇒ Matcher
Returns a new instance of Matcher.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 12 def initialize(fit_type, **) @fit_type = fit_type @threshold = .fetch(:threshold) { RSpec::Benchmark.configuration.fit_quality } @repeat = .fetch(:repeat) { RSpec::Benchmark.configuration.samples } @start = 8 @limit = 8 << 10 @ratio = 8 end |
Instance Method Details
#actual ⇒ Object
79 80 81 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 79 def actual @trend end |
#description ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 90 def description "perform #{@fit_type}" end |
#failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 95 def "expected block to #{description}, but #{failure_reason}" end |
#failure_message_when_negated ⇒ Object
99 100 101 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 99 def "expected block not to #{description}, but #{failure_reason}" end |
#failure_reason ⇒ Object
103 104 105 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 103 def failure_reason "performed #{actual}" end |
#in_range(start, limit = (not_set = true)) ⇒ Object
Specify range of inputs
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 ⇒ Object
32 33 34 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 32 def matcher_name "perform_#{@fit_type}" end |
#matches?(block) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 |
# 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) ⇒ Object
69 70 71 72 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 69 def ratio(ratio) @ratio = ratio self end |
#sample(repeat) ⇒ Object
74 75 76 77 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 74 def sample(repeat) @repeat = repeat self end |
#supports_block_expectations? ⇒ True
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates this matcher matches against a block
28 29 30 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 28 def supports_block_expectations? true end |
#threshold(threshold) ⇒ Object
64 65 66 67 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 64 def threshold(threshold) @threshold = threshold self end |
#times ⇒ Object
No-op, syntactic sugar.
85 86 87 |
# File 'lib/rspec/benchmark/complexity_matcher.rb', line 85 def times self end |