[rspec-users] Date Approximation in Specs

s.ross cwdinfo at gmail.com
Tue Jan 9 18:59:24 EST 2007

The floating-point expectations allow for an error tolerance. Is  
there any similar facility for dates? For example, say I have a  
custom class that handles date/time spans and I want to spec it:

context "A DateRange span" do
   specify "should know when a week ago is :)" do
     d = DateRange.new
     d.last_week.should_be_close_to(1.week.ago, 24*60*60)

The idea of should_be_close_to is to provide a tolerance. My class  
only is required to be accurate to the same day, and I want to  
express that in terms of "close_to" uncertainty. Is there a great  
baked-in way I'm missing?

I have code to do this in Test::Unit that I could port over if need  
be but I'd rather not if something better already exists.



More information about the rspec-users mailing list