1

我正在尝试编写一个测试登录的测试,然后以下测试使用第一个登录测试中的 cookie 集。

据我所知,这是完成的ydescribe

开始描述一个保存 cookie 的测试套件以及对测试的 Application 和 ConnectionPool 的引用

我试图通过查看 github repos 中的一些示例在我的应用程序中使用它,但没有运气。

这是我的代码:

module Handler.PostSpec ( spec ) where

import TestImport hiding (postBody)
import Data.Aeson
import Yesod.Test

spec :: Spec
spec =
    ydescribe "Auth" $ do
        yit "logs in to dummy auth" $ do
            request $ do
                addPostParam "ident" "0"
                setMethod "POST"
                setUrl ("http://localhost:3000/auth/page/dummy" :: Text)
            statusIs 303

编译时会出现错误:

test/Handler/PostSpec.hs:9:5: error:
    • Couldn't match type ‘transformers-0.5.2.0:Control.Monad.Trans.Writer.Lazy.WriterT
                             [YesodSpecTree site0] Identity ()’
                     with ‘hspec-core-2.4.4:Test.Hspec.Core.Spec.Monad.SpecM () ()’
      Expected type: Spec
        Actual type: YesodSpec site0
    • In the expression:
        ydescribe "Auth"
        $ do { yit "logs in to dummy auth"
               $ do { request $ do { ... };
                      statusIs 303 } }

      In an equation for ‘spec’:
          spec
            = ydescribe "Auth"
              $ do { yit "logs in to dummy auth"
                     $ do { request $ ...;
                            .... } }

使用 ydescribe 的正确方法是什么?

4

1 回答 1

0

发现我也必须使用 yesodSpec 并将 ydescribe 作为第二个参数传递。

这是一个使用示例。

spec :: Spec
spec = do
    settings <-
        runIO $ loadYamlSettings
            ["config/test-settings.yml", "config/settings.yml"]
            []
            useEnv
    foundation <- runIO $ makeFoundation settings
    yesodSpec foundation $ do
        ydescribe "Tests" $ do
            yit "Test" $ do
               -- Test something
于 2017-12-23T13:36:45.533 回答