Generate spec file
This commit is contained in:
parent
fd9610a6a0
commit
7cffdf5f6c
@ -9,6 +9,7 @@ import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as TIO
|
||||
import System.Directory (getDirectoryContents, doesFileExist)
|
||||
import Control.Monad (unless)
|
||||
|
||||
data RouteError = EmptyRoute
|
||||
| RouteCaseError
|
||||
@ -78,7 +79,11 @@ addHandlerFiles cabal (name, handlerFile) pattern methods = do
|
||||
modify cabal $ fixCabal name
|
||||
modify "config/routes" $ fixRoutes name pattern methods
|
||||
writeFile handlerFile $ mkHandler name pattern methods
|
||||
specExists <- doesFileExist specFile
|
||||
unless specExists $
|
||||
writeFile specFile $ mkSpec name pattern methods
|
||||
where
|
||||
specFile = "test/Handler/" ++ name ++ "Spec.hs"
|
||||
modify fp f = readFile fp >>= writeFile fp . f
|
||||
|
||||
getCabal :: IO FilePath
|
||||
@ -142,6 +147,24 @@ fixRoutes name pattern methods fileContents =
|
||||
]
|
||||
startingCharacter = if "\n" `isSuffixOf` fileContents then "" else "\n"
|
||||
|
||||
mkSpec :: String -> String -> String -> String
|
||||
mkSpec name _ methods = unlines
|
||||
$ ("module Handler." ++ name ++ "Spec (spec) where")
|
||||
: ""
|
||||
: "import TestImport"
|
||||
: ""
|
||||
: "spec :: Spec"
|
||||
: "spec = withApp $ do"
|
||||
: concatMap go (words methods)
|
||||
where
|
||||
go method =
|
||||
[ ""
|
||||
, " describe \"" ++ func ++ "\" $ do"
|
||||
, " error \"Spec not implemented: " ++ func ++ "\""
|
||||
, ""]
|
||||
where
|
||||
func = concat [map toLower method, name, "R"]
|
||||
|
||||
mkHandler :: String -> String -> String -> String
|
||||
mkHandler name pattern methods = unlines
|
||||
$ ("module Handler." ++ name ++ " where")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user