Created
August 11, 2016 22:47
-
-
Save Wizek/e3fb2d540b48d198299dea8f8bc7b48e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addTwoNumbers a b = add a b | |
add = (+) | |
tests = do | |
let addTwoNumbers = assemble defs "addTwoNumbers" | |
addTwoNumbers 3 4 `shouldBe` 7 | |
let addTwoNumbers = assemble defs{add=(*)} "addTwoNumbers" | |
addTwoNumbers 3 4 `shouldBe` 12 | |
time = getCurrentTime | |
yesterday = fmap (addTime ((-1) * 60 * 60 * 24)) time | |
timeRangeSinceYesterday = (,) <$> yesterday <*> time | |
tests2 = do | |
let trsy = assemble defs "timeRangeSinceYesterday" | |
trsy >>= (`shouldBe` ({- non-deterministic -})) | |
let trsy = assemble defs{time=return $ parseTime "2010-02-02 13:00"} "timeRangeSinceYesterday" | |
trsy >>= (`shouldBe` (arseTime "2010-02-01 13:00", arseTime "2010-02-02 13:00")) | |
-- always deterministic, mocked a time function that is 2 levels deep in the | |
-- call stack without having to pass it through its parents explicitly | |
-- | |
-- This benefit becomes more and more apparent the more dependencies we want | |
-- to be mockable, and the deeper the call hierarchy is. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment