Class: RSpec::SleepStudy
- Inherits:
-
Object
- Object
- RSpec::SleepStudy
- Defined in:
- lib/rspec/sleep_study.rb
Instance Method Summary collapse
- #dump_summary(_notification) ⇒ Object
- #example_ended(notification) ⇒ Object (also: #example_failed, #example_passed, #example_pending)
- #example_started(notification) ⇒ Object
-
#initialize(output) ⇒ SleepStudy
constructor
A new instance of SleepStudy.
Constructor Details
#initialize(output) ⇒ SleepStudy
Returns a new instance of SleepStudy.
8 9 10 11 12 13 14 15 16 |
# File 'lib/rspec/sleep_study.rb', line 8 def initialize(output) @output = output @sleepers = [] @locs_by_example = {} @tracers = [ TracePoint.new(:c_call) { |tp| start_sleep(tp) if tp.method_id == :sleep }, TracePoint.new(:c_return) { |tp| end_sleep if tp.method_id == :sleep } ] end |
Instance Method Details
#dump_summary(_notification) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/sleep_study.rb', line 35 def dump_summary(_notification) return unless sleepers_to_report.any? @output << "\nThe following examples spent the most time in `sleep`:\n" sleepers_to_report.each do |example, slept| @output << " #{slept.round(3)} seconds: #{example.location}\n" locs_to_report(example.id, slept).each do |loc, loc_slept| @output << " - #{loc_slept.round(3)} seconds: #{loc}\n" end end @output << "\n" end |
#example_ended(notification) ⇒ Object Also known as: example_failed, example_passed, example_pending
26 27 28 29 30 |
# File 'lib/rspec/sleep_study.rb', line 26 def example_ended(notification) @tracers.each(&:disable) @current_example = nil record_time_slept(notification) end |
#example_started(notification) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rspec/sleep_study.rb', line 18 def example_started(notification) @total_time_slept = 0 @sleep_starts = [] @tracers.each(&:enable) @locs_by_example[notification.example.id] = {} @current_example = notification.example end |