travisjeffery/timecop — pull request #124 by jemc (2014-07-08 00:16:02+00:00)
Title: Added opt-in feature to scale sleep operations.

A lot of my time-dependent code I work with uses sleep operations with specific timings for scheduling events. These time-dependent snippets are also coupled with the Time-related operations that Timecop already stubs, so the two types of operations always need to be stubbed together for me. I'm currently using some localized stubbing but I'm now finding it necessary to duplicate this code in several test, so I thought I'd submit a pull request to stub sleep when scale is called.

To be specific, it's usually `ConditionVariable#wait` and not `Kernel#sleep` that I use, but this pull request mocks both, because it is nearly the same operation.

This is a purely opt-in feature and shouldn't change the way `Timecop.scale` works for people already using Timecop in the workflows. You can opt-in to this expanded stubbing with `Timecop.scale_sleep = true`.

I've tried to match the existing style as much as possible in the implementation, the tests, and the explanation I added to the README (which is in a separate commit, so you can decide if you want it or not).

Let me know if you'd prefer some other way of enabling the feature instead of `Timecop.scale_sleep = true`, and I'd bet we can make it happen.

Thanks for your consideration, and great work so far with Timecop!