module TestProf::RSpecDissect
RSpecDissect tracks how much time do you spend in `before` hooks and memoization helpers (i.e. `let`) in your tests.
Constants
- METRICS
Public Class Methods
config()
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 78 def config @config ||= Configuration.new end
configure() { |config| ... }
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 82 def configure yield config end
init()
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 86 def init RSpec::Core::Example.prepend(ExampleInstrumentation) RSpec::Core::MemoizedHelpers::ThreadsafeMemoized.prepend(MemoizedInstrumentation) RSpec::Core::MemoizedHelpers::NonThreadSafeMemoized.prepend(MemoizedInstrumentation) @data = {} METRICS.each do |type| @data["total_#{type}"] = 0.0 end reset! log :info, "RSpecDissect enabled" end
memoization_available?()
click to toggle source
Whether we are able to track `let` usage
# File lib/test_prof/rspec_dissect.rb, line 121 def memoization_available? defined?(::RSpec::Core::MemoizedHelpers::ThreadsafeMemoized) end
meta_for(key)
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 129 def meta_for(key) @data[key.to_s][:meta] end
reset!()
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 114 def reset! METRICS.each do |type| @data[type.to_s] = {time: 0.0, meta: []} end end
time_for(key)
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 125 def time_for(key) @data[key.to_s][:time] end
total_time_for(key)
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 133 def total_time_for(key) @data["total_#{key}"] end
track(type, meta = nil) { || ... }
click to toggle source
# File lib/test_prof/rspec_dissect.rb, line 103 def track(type, meta = nil) start = TestProf.now res = yield delta = (TestProf.now - start) type = type.to_s @data[type][:time] += delta @data[type][:meta] << meta unless meta.nil? @data["total_#{type}"] += delta res end