@@ -15,11 +15,11 @@ import qualified Data.Conduit as C
1515import qualified Control.Monad.Trans.Resource as C
1616import qualified Data.Conduit.List as CL
1717
18−import System.Directory
1918import Control.Monad
2019import Control.Exception (try, SomeException)
2120import Test.Hspec
22−import Test.Hspec.Expectations.Contrib
21+import Data.Either.Compat
22+import Test.Mockery.Directory
2323
2424import qualified Data.Yaml as D
2525import Data.Yaml (object, array, (.=))
@@ -237,26 +237,17 @@ caseEncodeDecode = do
237237 yamlString = "foo: bar\nbaz:\n - bin1\n - bin2\n"
238238 yamlBS = B8.pack yamlString
239239
240−removeFile' :: FilePath -> IO ()
241−removeFile' fp = do
242− x <- doesFileExist fp
243− when x $ removeFile fp
244−
245240caseEncodeDecodeFile :: Assertion
246−caseEncodeDecodeFile = do
247− removeFile' tmpPath
241+caseEncodeDecodeFile = withFile "" $ \tmpPath -> do
248242 eList <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
249243 C.runResourceT $ CL.sourceList eList C.$$ Y.encodeFile tmpPath
250244 eList2 <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
251245 map MyEvent eList @=? map MyEvent eList2
252246 where
253247 filePath = "test/largest-string.yaml"
254− tmpPath = "tmp.yaml"
255248
256249caseInterleave :: Assertion
257−caseInterleave = do
258− removeFile' tmpPath
259− removeFile' tmpPath2
250+caseInterleave = withFile "" $ \tmpPath -> withFile "" $ \tmpPath2 -> do
260251 () <- C.runResourceT $ Y.decodeFile filePath C.$$ Y.encodeFile tmpPath
261252 () <- C.runResourceT $ Y.decodeFile tmpPath C.$$ Y.encodeFile tmpPath2
262253 f1 <- readFile tmpPath
@@ -264,8 +255,6 @@ caseInterleave = do
264255 f1 @=? f2
265256 where
266257 filePath = "test/largest-string.yaml"
267− tmpPath = "tmp.yaml"
268− tmpPath2 = "tmp2.yaml"
269258
270259caseDecodeInvalidDocument :: Assertion
271260caseDecodeInvalidDocument = do
@@ -308,8 +297,7 @@ caseEncodeDecodeData = do
308297 out @?= Just sample
309298
310299caseEncodeDecodeFileData :: Assertion
311−caseEncodeDecodeFileData = do
312− let fp = "tmp.yaml"
300+caseEncodeDecodeFileData = withFile "" $ \fp -> do
313301 D.encodeFile fp sample
314302 out <- D.decodeFile fp
315303 out @?= Just sample