Hacker News new | past | comments | ask | show | jobs | submit login
Why constant mocking in RSpec is bad (hqc.io)
2 points by hqc on March 26, 2017 | hide | past | favorite | 2 comments



    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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: