bebanjo / delorean Goto Github PK
View Code? Open in Web Editor NEWDISCONTINUED - Delorean lets you travel in time with Ruby by mocking Time.now
License: MIT License
DISCONTINUED - Delorean lets you travel in time with Ruby by mocking Time.now
License: MIT License
In some acceptance tests we generate documents and upload to S3. When time-travelled, S3 rejects the request with a RequestTimeTooSkewed error.
My workaround is a bit nasty, involving bookmarking time, returning to present, uploading the file, then traveling back to the bookmarked time - all within the file-upload method, essentially.
Is there a cleaner solution?
Due to the implementation of now
method milliseconds are lost when using Delorean.
$ rails console
ruby-1.9.3-p125-perf :001 > DateTime.now.strftime("%L")
=> "462"
ruby-1.9.3-p125-perf :002 > DateTime.now.strftime("%L")
=> "175"
ruby-1.9.3-p125-perf :003 > require 'delorean'
=> true
ruby-1.9.3-p125-perf :004 > DateTime.now.strftime("%L")
=> "000"
I'm getting the following error when I try to start the rails server. I'm trying to create a vagrant box for this app. I suspect something might be off with my env and not necessarily with delorean, so I was hoping someone might know if this is a symptom of something else.
Environment:
vagrant@precise64:~/myapp$ bundle exec rails s
/home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
/home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/delorean-2.1.0/lib/delorean.rb:16:in `alias_method': undefined method `today' for class `Class' (NameError)
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/delorean-2.1.0/lib/delorean.rb:16:in `singletonclass'
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/delorean-2.1.0/lib/delorean.rb:15:in `<top (required)>'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /home/vagrant/myapp/config/application.rb:8:in `<top (required)>'
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
from /home/vagrant/myapp/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I know the DeLorean isn't capable of freezing time, but it's handy with working with Time.now
Alternatively, maybe including some time matchers for RSPec would solve the same problem. :-)
DateTime.now returns current time while Time.now return the correct time after traveling in time using delorean with ruby 1.9.3.
Using ruby 1.9.2 everything works fine.
Update flux capacitor
I tried to require delorean in my model tests but I get a NameError.
What is the proper way to include the gem in my model tests?
Thanks
PS: I hope this is the right place to ask this.
rubygems has 2.1.0 but we don't have a tag for that release here.
Time.now.utc => 2012-02-29 18:33:42 UTC
Delorean.jump 30.days => nil
Time.now.utc => 2012-03-30 17:33:45 UTC
Some how we are loosing one hour.
I'm packaging delorean for debian and since the gem does not have specs in it, I have to download a github tarball. It would be nice to have the spec folder included in the gem itself, like many gems already do.
is this gem any different from timecop?
http://github.com/jtrupiano/timecop
why not just fork timecop?
Hi,
I observed the following in my test cases:
ree-1.8.7-2011.03 :001 > Delorean.time_travel_to DateTime.strptime("2011-05-25 18:00", "%Y-%m-%d %H:%M")
=> nil
ree-1.8.7-2011.03 :002 > Time.now
=> Wed May 25 00:00:02 +0200 2011
It seems that the Delorean does not consider the hours. There is a workaround, though: I can use jump after calling time_travel_to
Cheers,
Zsolt
I have tried all this convinations:
config.gem 'delorian'
config.gem 'delorian', :source => "http://gemcutter.org"
config.gem 'delorian', :source => 'http://gems.github.com'
I am very clumsy with all this about gems, so maybe is my fault.
This are my console log:
$ sudo rake gems:install RAILS_ENV=test
(in /Develop/test)
gem install delorian --source http://gems.github.com
ERROR: could not find gem delorian locally or in a repository
$ sudo rake gems:install RAILS_ENV=test
(in /Develop/test)
gem install delorian --source http://gemcutter.org
ERROR: could not find gem delorian locally or in a repository
$ sudo rake gems:install RAILS_ENV=test
(in /Develop/test)
gem install delorian
ERROR: could not find gem delorian locally or in a repository
$ sudo gem install delorean
Successfully installed delorean-0.2.0
1 gem installed
Installing ri documentation for delorean-0.2.0...
Installing RDoc documentation for delorean-0.2.0...
$ sudo rake gems RAILS_ENV=test
(in /Develop/test)
- [ ] delorian
Any suggestion?
Thanks
f.
Hi!
I was trying to test my expiring activeness of product (just scope in activerecord):
scope :active, where('expires_at > now()')
but Delorean only travels in ruby time, not in db time :) I know it is highly impossible to mock db time. but maybe somebody have some idea about it? maybe it is better not to use database specific methods, such as random() or now(), but pass for example Time.now converted to database date format? something like this:
scope :active, where("expires_at > #{Time.now}")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.