Skip to content

Instantly share code, notes, and snippets.

@DNNX
Created July 11, 2011 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNNX/1075473 to your computer and use it in GitHub Desktop.
Save DNNX/1075473 to your computer and use it in GitHub Desktop.

This simple framework allows you to assert things that should happen tomorrow*. For example:

assert_tomorrow { Time.now.wday == 2 } # => :passed
                                       # assuming today is Monday (i.e. wday == 1)

Another example shows that the time will never be the same again:

today = Time.now
assert_tomorrow { Time.now == today } # => :failed

And sometimes we can't event assert something for sure, because my expectation is too complex!

assert_tomorrow { _why is back }      # => :error

Of course, there is a lot room for improvement. You can introduce you own DSL and run tests against your life, for example:

me = Dnnx.instance.clone
assert_tomorrow do 
  future_me = Dnnx.instance 
  future_me.is_better_than me
end

*I didn't invent a time machine, so you have to wait 1 day for test result.

def assert_tomorrow() sleep(24*60*60); (yield ? :passed : :failed) rescue :error end
@jeffkreeftmeijer
Copy link

This is certainly the best way to test if something will happen tomorrow without cheating and using a time machine. Awesome work! ;)

@bltavares
Copy link

Funny

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment