2017-12-21 35 views
1

하나의 테스트가 로그인하고 다음 테스트에서 첫 번째 로그인 테스트의 쿠키 세트를 사용하는 테스트를 작성하려고합니다. 내가 무엇을 볼 수에서 Yesod.Test의 ydescribe는 어떻게 사용됩니까?

,이는 내가 github의의의 repos에서 몇 가지 예를 보면 내 응용 프로그램에서 이것을 사용하는 시도했지만 운이 없었 ydescribe

Start describing a Tests suite keeping cookies and a reference to the tested Application and ConnectionPool

으로 이루어집니다. ydescribe를 사용하는

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 $ ...; 
          .... } } 

어떤 것이 올바른 방법 :이 오류를 제공 컴파일 할 때

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 

:

여기 내 코드입니까?

+0

'spec'값에 잘못된 서명이 있다고 생각합니다. 작업 예제를 위해 yesod 스캐 폴딩 ('stack new foo yesod-simple')을 확인하십시오. –

답변

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