2017-12-21 23 views
1

私は1つのテストがサインインして、次のテストで最初のサインインテストからのクッキーセットを使用するテストを作成しようとしています。Yesod.Testのydescribeはどのように使用されていますか?

私が見ることができるものから、これは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を使用する正しい方法でしょうか?

+0

私は、あなたが 'spec'値に対して間違った署名をしていると思います。動作例については、yesod scaffolding( 'new foo yesod-simple'をスタック)をチェックしてください。 –

答えて

0

私はyesodSpecも使用し、ydescribeを2番目のパラメータとして渡す必要があります。

ここでは使用例を示します。

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 
関連する問題