Module: TestProf::RSpecDissect
- Extended by:
- Logging
- Defined in:
- lib/test_prof/rspec_dissect.rb,
lib/test_prof/rspec_dissect/rspec.rb
Overview
RSpecDissect tracks how much time do you spend in ‘before` hooks and memoization helpers (i.e. `let`) in your tests.
Defined Under Namespace
Modules: ExampleInstrumentation, MemoizedInstrumentation
Classes: Configuration, Listener
Constant Summary
collapse
- METRICS =
%w[before memo].freeze
Constants included
from Logging
Logging::COLORS
Class Method Summary
collapse
Methods included from Logging
build_log_msg, colorize, log
Class Method Details
.config ⇒ Object
55
56
57
|
# File 'lib/test_prof/rspec_dissect.rb', line 55
def config
@config ||= Configuration.new
end
|
59
60
61
|
# File 'lib/test_prof/rspec_dissect.rb', line 59
def configure
yield config
end
|
.init ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/test_prof/rspec_dissect.rb', line 63
def init
RSpec::Core::Example.prepend(ExampleInstrumentation)
if memoization_available?
RSpec::Core::MemoizedHelpers::ThreadsafeMemoized.prepend(MemoizedInstrumentation)
RSpec::Core::MemoizedHelpers::NonThreadSafeMemoized.prepend(MemoizedInstrumentation)
end
@data = {}
METRICS.each do |type|
@data["total_#{type}"] = 0.0
end
reset!
log :info, "RSpecDissect enabled"
end
|
.memoization_available? ⇒ Boolean
Whether we are able to track ‘let` usage
99
100
101
|
# File 'lib/test_prof/rspec_dissect.rb', line 99
def memoization_available?
defined?(::RSpec::Core::MemoizedHelpers::ThreadsafeMemoized)
end
|
.reset! ⇒ Object
92
93
94
95
96
|
# File 'lib/test_prof/rspec_dissect.rb', line 92
def reset!
METRICS.each do |type|
@data[type.to_s] = 0.0
end
end
|
.track(type) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/test_prof/rspec_dissect.rb', line 82
def track(type)
start = TestProf.now
res = yield
delta = (TestProf.now - start)
type = type.to_s
@data[type] += delta
@data["total_#{type}"] += delta
res
end
|