Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make freeze/travel return result of the block, instead of current time #2

Closed
madadam opened this issue Sep 25, 2009 · 1 comment
Closed

Comments

@madadam
Copy link

madadam commented Sep 25, 2009

Hello,

Would it be possible to change the implementation so the freeze/travel methods return the result of the passed in block, instead of current time? I think that would be more useful, because then you could do something like this:

user = Timecop.freeze(2.years.ago) { User.create!(:name => '...') }

Instead of this:

user = nil
Timecop.freeze(2.years.ago) do
  user  = User.create!(:name => '...')
end

I think that first line is necessary, because otherwise the user variable is lost when it comes out of block's scope.

@jtrupiano
Copy link
Collaborator

This is an interesting use case, one that I've never really used Timecop for. I'm not 100% sold on the change...I like the consistency of returning Time.now from all 3 functions (freeze, travel, return). Furthermore, you can invoke #freeze and #travel without passing a block.

Can you get away with using an instance variable (@user)? That will eliminate the need to define the variable prior to the method call.

It would be trivial to apply the change you're asking for, but I don't think I'm going to add it to the library. I know its not ideal, but it would be pretty simple to maintain your own fork. This library, though only versioned 0.3.0, is pretty mature. I don't foresee many changes to the codebase moving forward.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants