Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- a component
- data FileSystem m = FileSystem {
- exists :: Path -> m (Either Text Bool)
- , readFile :: Path -> m (Either Text Text)
- }
- -- a constructor for a mock file system
- newFileSystemWith :: (FileSystemValues -> FileSystemValues) -> FileSystem
- newFileSystemWith f = FileSystem {
- exists = \_ -> pure (_exists $ f fileSystemValues)
- , readFile = \_ -> pure (_readFile $ f fileSystemValues)
- }
- -- mocked returned values
- data FileSystemValues = FileSystemValues {
- _exists :: Either Text Bool
- , _read :: Either Text Text
- }
- fileSystemValues = FileSystemValues
- (Left "todo - exists")
- (Left "todo - readFile")
- -- set mock values
- existingFiles v = v { _exists = Right True }
- someText t v = v { _read = Right t }
- -- create a mock and compose functions to set return values
- myMock = newFileSystemWith (existingFiles . someText "hello world")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement