Narnach / freeze_time
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
tree d0313401e9ab038eb5a1d5db34ca7783483911c5
parent b01885b0fa5465f1d6eaad12febae7422c0b1138
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
MIT-LICENSE | ||
| |
Rakefile | ||
| |
freeze_time.gemspec | ||
| |
lib/ | ||
| |
readme.rdoc | ||
| |
spec/ |
FreezeTime
Every once in a while you have a need to freeze time in your tests or specs. Usually the code that does it is ugly code, like in this example that uses rspec:
frozen_time = Time.now Time.stub!(:now).and_return(frozen_time) Foo.bar.should == frozen_time
You need to read three dense lines to understand that time is frozen and that Foo.bar should return the current time. What if this could be a lot more intention revealing?
freeze_time do |time|
Foo.bar.should == time
end
FreezeTime helps you test code that requires time to be frozen. It does this by implementing Object#freeze_time, which allows you to freeze time for the duration of the block. This makes your code more intention revealing and a lot more pleasant to look at.
Installation
If you are using gemcutter.org, installation is easy:
gem install freeze_time
The alternative is to build and install the gem by hand:
git clone git://github.com/Narnach/freeze_time.git cd freeze_time rake install
There are no external dependencies and it should be compatible with all testing frameworks.
Contributors
Wes Oldenbeuving [github.com/Narnach]

