Hacker News new | ask | show | jobs
by al2o3cr 3378 days ago

    What if there are some core classes or third-party
    libraries we use also require Time.now to work?
The "once" expectation will fail, indicating that the mock doesn't accurately represent the behavior of the system?

Note that in the DI case, unless there's additional work being done to inject the double everywhere else `Time.now` gets used the spec will silently use the built-in version.

1 comments

Yeah that kind of test tends to be fragile and the outcome is unpredictable.

There's no need to inject the double everywhere in other tests because the built-in version is the behavior we want the function to work.