public
Description: A gem providing “time travel” and “time freezing” capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
Homepage: http://www.smartlogicsolutions.com/open-source-projects
Clone URL: git://github.com/jtrupiano/timecop.git
commit  01c777e256f25918c39181b416b0531b9fbe10bf
tree    50b5967c30f237ddaa302af2c808adb6d2bf9a35
parent  db589b1ae1397516447446dc5ab79f516936955a
name age message
file History.txt Loading commit data...
file Manifest.txt
file README.txt
file Rakefile
directory lib/
directory test/
file timecop.gemspec
README.txt
= timecop

* http://github.com/jtrupiano/timecop

== DESCRIPTION:

A gem providing simple ways to (temporarily) override Time.now, Date.today, and DateTime.now.  It provides "time travel" 
capabilities, making it dead simple to write test time-dependent code.

== FEATURES:

* Temporarily (or permanently if you prefer) change the concept of Time.now, DateTime.now (if defined), and Date.today 
(if defined)
* Timecop#travel api allows an argument to be passed in as one of: 1) Time instance, 2) DateTime instance, 3) Date 
instance,
  4) individual arguments (year, month, day, hour, minute, second)
* Nested calls to Timecop#travel are supported -- each block will maintain it's interpretation of now.

== SHORTCOMINGS:

* Currently, time will stand still during a call to #travel.  The following scheme (when implemented) should be able to 
provide this functionality:
  1) Take the new time/date from the #travel() function and store it.
  2) Compute deltas (offsets) for Time.now, DateTime.now and Date.today as compared to the instance passed in #travel
  3) Mock Time.now, DateTime.now and Date.today to return the current time + those deltas (rather than just returning 
  the original mock)

== SYNOPSIS:

* Run a time-sensitive test:
<code>
  joe = User.find(1)
  joe.purchase_home()
  assert !joe.mortgage_due?
  # move ahead a month and assert that the mortgage is due
  Timecop.travel(Date.today + 30) do
    assert joe.mortgage_due?
  end
</code>

* Set the time for the test environment of a rails app -- this is particularly helpful if your whole application
  is time-sensitive.  It allows you to build your test data at a single point in time, and to move in/out of that
  time as appropriate (within your tests)
  
in config/environments/test.rb

<code>
config.after_initialize do
  # Set Time.now to September 1, 2008 10:05:00 AM
  t = Time.local(2008, 9, 1, 10, 5, 0)
  Timecop.travel(t)
end
</code>

== REQUIREMENTS:

* None

== INSTALL:

* sudo gem install timecop (latest stable version from rubyforge)
* sudo gem install jtrupiano-timecop (HEAD of the repo from github)

== LICENSE:

(The MIT License)

Copyright (c) 2008 FIX

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.