Skip to content

Instantly share code, notes, and snippets.

@dcorking
Last active May 17, 2017 07:58
Show Gist options
  • Save dcorking/30b452d923b2ef6bc8b8873720f83f4c to your computer and use it in GitHub Desktop.
Save dcorking/30b452d923b2ef6bc8b8873720f83f4c to your computer and use it in GitHub Desktop.
rails_helper or spec_helper snippet to trace the clock before and after each rspec example
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
# ...
RSpec.configure do |config|
# Can help you spot problems with system time, timezones and time travel,
# especially if multiple specs interact with each other
# Check this doc for the difference between ::now and ::current :
# http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html#method-i-travel_to
config.around(:each) do |example|
puts "Time.now: #{Time.now}"
puts "Time.current: #{Time.current}"
example.run
puts "Time.now: #{Time.now}"
puts "Time.current: #{Time.current}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment