time_tracker_spec.rb 612 B

123456789101112131415161718192021
  1. require 'rails_helper'
  2. describe TimeTracker do
  3. describe "#track" do
  4. it "tracks execution time" do
  5. tracked_result = TimeTracker.track { sleep(0.01) }
  6. expect(tracked_result.elapsed_time).to satisfy {|v| v > 0.01 && v < 0.1}
  7. end
  8. it "returns the proc return value" do
  9. tracked_result = TimeTracker.track { 42 }
  10. expect(tracked_result.result).to eq(42)
  11. end
  12. it "returns an object that behaves like the proc result" do
  13. tracked_result = TimeTracker.track { 42 }
  14. expect(tracked_result.to_i).to eq(42)
  15. expect(tracked_result + 1).to eq(43)
  16. end
  17. end
  18. end