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

end_travel to remove stubs from travel and travel_to #12966

Closed
wants to merge 1 commit into from

Conversation

senny
Copy link
Member

@senny senny commented Nov 20, 2013

This is a follow up to #12824.

This patch introduces a new method called end_travel to remove the stubs from Time.now and Date.today. This is useful to set your tim in setup hooks and return to the original state in teardown.

To illustrate I updated a test within AR that used some custom stubbing logic.

I'm opening the PR to discuss and find the best name for the method end_travel. While brainstorming we thought about untravel, return, go_back, back and settled for end_travel.

@senny
Copy link
Member Author

senny commented Nov 20, 2013

@fxn as discussed.

/cc @sikachu @rafaelfranca @dhh

@senny
Copy link
Member Author

senny commented Nov 20, 2013

Reading this comment I realize that the stubs are cleaned after every run anyway and my example with setup / teardown is not really a valid use case for end_travel.

Should we still provide this functionality to return back? If we decide not to include the method we should at least document that the stubs are cleared after every test.

@fxn
Copy link
Member

fxn commented Nov 20, 2013

I'd prefer to have a use-case that justifies it (as this one seemed to).

@dmathieu
Copy link
Contributor

I don't see any use of end_travel which can't just be replaced with a block, which I would believe to be a better way of doing things.

@fxn
Copy link
Member

fxn commented Nov 20, 2013

By the way, this tells us it should be explained in the docs. It works that way because of the implementation, but that behaviour belongs to the public interface.

@senny
Copy link
Member Author

senny commented Nov 20, 2013

Agreed. I'm replacing the end_travel commit with documentation.

@carlosantoniodasilva
Copy link
Member

If we are allowing users to "travel"/stub at any time in a given test, I think we should allow them to stop that at any time too, either using a block or being explicit. Just my 2 cents.

@sikachu
Copy link
Member

sikachu commented Jan 24, 2014

Since this has been a while, and seems like the use case can be justified by using a block version, I'm closing this PR for now.

@sikachu sikachu closed this Jan 24, 2014
@chancancode
Copy link
Member

In the original discussion, one of the arguments against adding it is that stubs will be automatically cleaned after each test anyway. However, that seems to be a mocha feature. Now that we are removing the mocha dependency for this feature, does that still work?

@rafaelfranca
Copy link
Member

Both my implementations have one hook to make this feature work but I'd love to remove it. The reason is, right now the hook only work with minitest. If the project is using cucumber or rspec users will have to know and use an internal feature of Rails to avoid stubs to leak between tests cases.

@chancancode
Copy link
Member

Right, so if we don't want to make people mess with private APIs to make alternative test frameworks work, we would have to expose one of internal_unstub or end_travel, correct? In that case I think we should expose the latter.

@chancancode chancancode reopened this Jan 24, 2014
@carlosantoniodasilva
Copy link
Member

Maybe we should just move that to the way we expect it to be used: either use a block, which unstub at the end for you, or make sure you clean the stub yourself on an after hook. Nothing automatic, and docs would explain that. Other Ruby APIs work similarly right?

@rafaelfranca
Copy link
Member

Right. But I don't think we should expose internal_unstub. I prefer to have an end_travel to let users make sure they cleaned the stub themself.

@chancancode
Copy link
Member

👍—
Sent from Mailbox for iPhone

On Fri, Jan 24, 2014 at 8:50 AM, Rafael Mendonça França
notifications@github.com wrote:

Right. But I don't think we should expose internal_unstub. I prefer to have an end_travel to let users make sure they cleaned the stub theyself.

Reply to this email directly or view it on GitHub:
#12966 (comment)

@carlosantoniodasilva
Copy link
Member

Yup, end_travel it is. 👍

@senny
Copy link
Member Author

senny commented Jan 30, 2014

Closing in favor of #13884

@senny senny closed this Jan 30, 2014
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

Successfully merging this pull request may close these issues.

7 participants