File: ConfigSpec.hs

package info (click to toggle)
haskell-hspec-core 2.11.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 656 kB
  • sloc: haskell: 8,945; makefile: 5
file content (46 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE CPP #-}
module Test.Hspec.Core.ConfigSpec (spec) where

import           Prelude ()
import           Helper

import           System.Directory

import           Test.Hspec.Core.Config

spec :: Spec
spec = around_ inTempDirectory $ around_ (withEnvironment [("HOME", "foo")]) $ do
  describe "readConfig" $ do
    it "recognizes options from HSPEC_OPTIONS" $ do
      withEnvironment [("HSPEC_OPTIONS", "--color")] $ do
        configColorMode <$> readConfig defaultConfig [] `shouldReturn` ColorAlways

    it "recognizes options from HSPEC_*" $ do
      withEnvironment [("HSPEC_COLOR", "yes")] $ do
        configColorMode <$> readConfig defaultConfig [] `shouldReturn` ColorAlways

  describe "readConfigFiles" $ do
    it "reads .hspec" $ do
      dir <- getCurrentDirectory
      let name = dir </> ".hspec"
      writeFile name "--diff --foo 'bar baz'"
      readConfigFiles `shouldReturn` [(name, ["--diff", "--foo", "bar baz"])]

#ifndef mingw32_HOST_OS
    it "reads ~/.hspec" $ do
      let name = "my-home/.hspec"
      createDirectory "my-home"
      writeFile name "--diff"
      withEnvironment [("HOME", "my-home")] $ do
        readConfigFiles `shouldReturn` [(name, ["--diff"])]

    context "without $HOME" $ do
      it "returns empty list" $ do
        readConfigFiles `shouldReturn` []

    context "without current directory" $ do
      it "returns empty list" $ do
        dir <- getCurrentDirectory
        removeDirectory dir
        readConfigFiles `shouldReturn` []
#endif