Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Delorean lets you travel in time with Ruby by mocking
Latest commit cd675b6 @cavalle cavalle Version 2.1.0

Delorean Build Status

Delorean lets you travel in time with Ruby by mocking

Marty:: Wait a minute, Doc. Ah... Are you telling me that you built a time machine... out of a DeLorean?

Doc:: The way I see it, if you're gonna build a time machine into a car, why not do it with some style?


$ [sudo] gem install delorean

Or add it to your Gemfile, etc.


Let's travel in time!

require 'delorean'

# => Wed Feb 24
Delorean.time_travel_to "1 month ago" # => Sun Jan 24
Delorean.back_to_the_present          # => Wed Feb 24

With a block:

Delorean.time_travel_to("1 month ago") do
  # Inside the block, => Sun Jan 24 00:34:32 +0100 2010
  # And the time still goes by... => Sun Jan 24 00:34:37 +0100 2010

# Outside the block, => Wed Feb 24 00:34:35 +0100 2010

You can also jump which is like sleep but without losing time

# => Wed Feb 24 00:34:04 +0100 2010
Delorean.jump 30
# => Wed Feb 24 00:34:34 +0100 2010


Time-travelling can be extremely useful when you're testing your application.

For example, in RSpec you may find convenient to include Delorean's DSL in your spec_helper.rb:

RSpec.configure do |config|
  config.include Delorean

Now you can time-travel in your examples, like this:

it "should show latest created user" do

  time_travel_to(3.minutes.ago) { create_user :name => "John"  }
  time_travel_to(5.minutes.ago) { create_user :name => "Chris" }

  get 'show'

  response.should have_text("John")
  response.should_not have_text("Chris")


Don't forget to go back to the present after each example:

after(:each) { back_to_the_present }

or its alternate syntax:

after(:each) { back_to_1985 }


Delorean image based on an original by Giancarlo Pitocco.

Copyright (c) 2012 Luismi Cavallé, Sergio Gil and BeBanjo S.L. released under the MIT license

Something went wrong with that request. Please try again.