Skip to content

Instantly share code, notes, and snippets.

@orend
Last active August 29, 2015 13:56
Show Gist options
  • Save orend/9099893 to your computer and use it in GitHub Desktop.
Save orend/9099893 to your computer and use it in GitHub Desktop.
Time travel and dependencies
def age(with_respect_to = Time.now)
...
end
@orend
Copy link
Author

orend commented Feb 19, 2014

continuing the discussion from rails/rails#12824 (comment)

@orend
Copy link
Author

orend commented Feb 19, 2014

@fxn - to answer your question: I would test that the age of the user is shown in his profile page but not by asserting the exact age. I think this will be over-testing. In the collaborators' unit test you'd have set expectations that the age method is being called, and in age's unit test you'd test it does the right thing - performing the correct calculation with respect to the given parameter. In the integration test I'd maybe test that the displayed age is numeric and between 0 and 150. No need to test ``age`'s logic again. The default code for the parameter will get executed and if it was a typo or something that doesn't make sense it would get caught in the integration test.

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