Yesod.Test 中的 ydescribe 如何使用?
How is ydescribe from Yesod.Test used?
我正在尝试编写测试,其中一个测试登录,然后以下测试使用第一次登录测试中设置的 cookie。
据我所知,这是用 ydescribe
完成的
Start describing a Tests suite keeping cookies and a reference to the tested Application and ConnectionPool
我试图通过查看 github 存储库中的一些示例在我的应用程序中使用它,但没有成功。
这是我的代码:
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 的正确使用方法是什么?
发现我也必须使用 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
我正在尝试编写测试,其中一个测试登录,然后以下测试使用第一次登录测试中设置的 cookie。
据我所知,这是用 ydescribe
Start describing a Tests suite keeping cookies and a reference to the tested Application and ConnectionPool
我试图通过查看 github 存储库中的一些示例在我的应用程序中使用它,但没有成功。
这是我的代码:
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 的正确使用方法是什么?
发现我也必须使用 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