Class: Perfgate::RSpec::WorkloadBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/perfgate/rspec/workload_builder.rb

Overview

Builds a Workloads::Workload that wraps a single RSpec example.

Each call re-instantiates the example group and re-runs the example via RSpec's own Example#run(instance, reporter), which is safe to invoke repeatedly: it resets the example's execution result and exercises the full before/around/after hook chain each time (spec section 12.2, "reset workload state" + "execute measured samples"). A ::RSpec::Core::NullReporter discards RSpec's own reporting, since Baseline does its own result collection.

Instance Method Summary collapse

Constructor Details

#initialize(defaults:) ⇒ WorkloadBuilder

Returns a new instance of WorkloadBuilder.



18
19
20
# File 'lib/perfgate/rspec/workload_builder.rb', line 18

def initialize(defaults:)
  @defaults = defaults
end

Instance Method Details

#build(example) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/perfgate/rspec/workload_builder.rb', line 22

def build(example)
  options = example.[:perfgate]
  options = {} unless options.is_a?(Hash)

  Workloads::Workload.new(
    id: IdResolver.resolve(example),
    samples: options.fetch(:samples, @defaults.fetch(:samples)),
    warmup: options.fetch(:warmup, @defaults.fetch(:warmup)),
    metrics: options.fetch(:metrics, @defaults.fetch(:metrics))
  ) { run_example(example) }
end