Module: TestProf::RSpecDissect
- Extended by:
- Logging
- Defined in:
- lib/test_prof/rspec_dissect.rb,
lib/test_prof/rspec_dissect/rspec.rb,
lib/test_prof/rspec_dissect/collectors/let.rb,
lib/test_prof/rspec_dissect/collectors/base.rb,
lib/test_prof/rspec_dissect/collectors/before.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: Collectors, ExampleInstrumentation, MemoizedInstrumentation
Classes: Configuration, Listener
Constant Summary
collapse
- METRICS =
%w[before let].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
78
79
80
|
# File 'lib/test_prof/rspec_dissect.rb', line 78
def config
@config ||= Configuration.new
end
|
82
83
84
|
# File 'lib/test_prof/rspec_dissect.rb', line 82
def configure
yield config
end
|
.init ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# 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? ⇒ Boolean
Whether we are able to track ‘let` usage
121
122
123
|
# File 'lib/test_prof/rspec_dissect.rb', line 121
def memoization_available?
defined?(::RSpec::Core::MemoizedHelpers::ThreadsafeMemoized)
end
|
129
130
131
|
# File 'lib/test_prof/rspec_dissect.rb', line 129
def meta_for(key)
@data[key.to_s][:meta]
end
|
.reset! ⇒ Object
114
115
116
117
118
|
# 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) ⇒ Object
125
126
127
|
# File 'lib/test_prof/rspec_dissect.rb', line 125
def time_for(key)
@data[key.to_s][:time]
end
|
.total_time_for(key) ⇒ Object
133
134
135
|
# File 'lib/test_prof/rspec_dissect.rb', line 133
def total_time_for(key)
@data["total_#{key}"]
end
|
.track(type, meta = nil) ⇒ Object
103
104
105
106
107
108
109
110
111
112
|
# 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
|