Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created December 23, 2011 10:21
Show Gist options
  • Save shaneriley/1513808 to your computer and use it in GitHub Desktop.
Save shaneriley/1513808 to your computer and use it in GitHub Desktop.
Faking the time for tests' sake
// app/assets/env/test/time.js
window.__rails_test_time = Date();
// Or for you CS guys
@.__rails_test_time = Date()
In your JS that uses a cached Time.now-style date object, use this for assignment:
var now = window.__rails_test_time || Date();
Then conditionally include your test JS like so:
= javascript_include_tag "env/test/time" if Rails.env.test?
// .-.
// |U|
// | |
// | |-._
// | | | |-.
// /| ` |
// | | | LIKE
// | | SO:
// \ /
// | |
// | |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment