Guest User

Untitled

a guest
Jun 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # delorean.rb
  2.  
  3. require File.dirname(__FILE__) + '/../spec_helper'
  4. require RAILS_ROOT + "/lib/current_time"
  5.  
  6. describe CurrentTime do
  7.  
  8. describe "with_current_time" do
  9.  
  10. it "should travel through time" do
  11. two_weeks_ago = 2.weeks.ago
  12. with_current_time(two_weeks_ago) do
  13. Time.now.should be_close(two_weeks_ago, 1.second)
  14. Date.today.should == two_weeks_ago.to_date
  15. end
  16. end
  17.  
  18. it "should return to the future" do
  19. today = Date.today
  20. with_current_time(2.weeks.ago) {}
  21. Date.today.should == today
  22. end
  23.  
  24. it "should travel through time several times" do
  25. expected = (1.year - 2.weeks).ago.to_date
  26. with_current_time(1.year.ago) do
  27. with_current_time(2.weeks.from_now) do
  28. Date.today.should == expected
  29. end
  30. end
  31. end
  32.  
  33. it "should still return to the future" do
  34. today = Date.today
  35. with_current_time(2.weeks.ago) do
  36. with_current_time(1.year.from_now) {}
  37. end
  38. Date.today.should == today
  39. end
  40.  
  41. end
  42. end
Add Comment
Please, Sign In to add comment