Class: RSpec::Hermetic::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/hermetic/snapshot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, errors: {}, timings: {}) ⇒ Snapshot

Returns a new instance of Snapshot.



8
9
10
11
12
# File 'lib/rspec/hermetic/snapshot.rb', line 8

def initialize(data:, errors: {}, timings: {})
  @data = data
  @errors = errors
  @timings = timings
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/rspec/hermetic/snapshot.rb', line 6

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/rspec/hermetic/snapshot.rb', line 6

def errors
  @errors
end

#timingsObject (readonly)

Returns the value of attribute timings.



6
7
8
# File 'lib/rspec/hermetic/snapshot.rb', line 6

def timings
  @timings
end

Class Method Details

.capture(probes, context: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/hermetic/snapshot.rb', line 14

def self.capture(probes, context: nil)
  data = {}
  errors = {}
  timings = {}

  probes.each do |probe|
    started_at = monotonic_now
    data[probe.name] = probe.capture(context)
  rescue StandardError => error
    errors[probe.name] = "#{error.class}: #{error.message}"
    data[probe.name] = {}
  ensure
    timings[probe.name] = monotonic_now - started_at if started_at
  end

  new(data: data, errors: errors, timings: timings)
end

.monotonic_nowObject



32
33
34
# File 'lib/rspec/hermetic/snapshot.rb', line 32

def self.monotonic_now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end