Wynn Netherland changelog.com/posts

Delorean - mock Ruby's Time.now with style

Delorean photo courtesy Giancarlo Pitocco

At The Changelog, we give bonus points for witty project names. How could we pass up a repo named Delorean.

Delorean is a smart way to mock Ruby’s Time.now method thereby allowing you to travel in time. Why is this helpful? Testing. Consider the following spec from the README:

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")

end

Want to get back to 1985?

after(:each) { back_to_the_present }

Brilliant!

[Source on GitHub] [Back to the Future on IMDB for you youngsters]


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00