on master help sign in
Merge pull request #61 from zalora/test-tweaks

spec: Do not write files into current directory

commit963ba05663c003078ee3faf526793722bdef8580 authorMichael Snoyman <michael@snoyman.com> dateSun 31 May 2015, 13:27 (11 years ago) parentc5002146f0fcac
4 files changed+8−22
.gitignore−2 test/Data/Yaml/IncludeSpec.hs+1−1 test/Data/YamlSpec.hs+5−17 yaml.cabal+2−2
.gitignore−2
@@ -1,7 +1,5 @@
11dist
22*.swp
3−tmp.yaml
4−tmp2.yaml
53cabal-dev/
64.cabal-sandbox/
75cabal.sandbox.config
test/Data/Yaml/IncludeSpec.hs+1−1
@@ -2,7 +2,7 @@
22module Data.Yaml.IncludeSpec (main, spec) where
33
44import Test.Hspec
5−import Test.Hspec.Expectations.Contrib
5+import Data.Either.Compat
66import Data.Aeson
77import Data.Aeson.QQ
88import Data.Yaml (ParseException)
test/Data/YamlSpec.hs+5−17
@@ -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
yaml.cabal+2−2
@@ -114,9 +114,7 @@ test-suite spec
114114 Data.Yaml.IncludeSpec
115115 cpp-options: -DTEST
116116 build-depends: hspec >= 1.3
117− , hspec-expectations
118117 , HUnit
119− , directory
120118 , base >= 4 && < 5
121119 , transformers >= 0.1
122120 , bytestring >= 0.9.1.4
@@ -128,6 +126,8 @@ test-suite spec
128126 , vector
129127 , resourcet
130128 , aeson-qq
129+ , mockery
130+ , base-compat
131131 ghc-options: -Wall
132132
133133source-repository head