Created
December 23, 2011 10:21
-
-
Save shaneriley/1513808 to your computer and use it in GitHub Desktop.
Faking the time for tests' sake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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