Timecop is fun, but you don't need a whole gem for that. Just use
Time.stub(:now), e.g.
describe "time" do
before do
@fake_time = Time.now
Time.stub(:now) { @fake_time }
end
it "is equal" do
Time.now.should == Time.now # now it passes
end
it "is close" do
Time.now.should be_within(0.1).of(Time.now)
end
end
It's easy to move @fake_time around in the middle of a spec, too, to
simulate time passing or to zap over to e.g. the moment when daylight
savings happens.
- A
On Thu, Jul 5, 2012 at 1:01 PM, Antonio Antillon <[email protected]> wrote:
> If you are testing that date/time match... try using the timecop gem, so you
> can 'freeze' time.
> https://github.com/jtrupiano/timecop
>
>
>
> On Thu, Jul 5, 2012 at 12:20 PM, Tsvetelina Borisova
> <[email protected]> wrote:
>>
>> I have this in one rspec test:
>> expected: Thu, 05 Jul 2012 19:07:31 UTC +00:00
>> got: Thu, 05 Jul 2012 19:07:31 UTC +00:00
>>
>> Do you know how to tell to rspec not to consider the miliseconds? Thanks
>> in advance : )
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "rspec" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/rspec/-/UngzRJ7DbbcJ.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/rspec?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rspec?hl=en.
--
Alex Chaffee - [email protected]
http://alexchaffee.com
http://twitter.com/alexch
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rspec?hl=en.