spec :: Spec
spec = withApp $ describe "WebApi response" $ do
  context "Simple Response" $ do
    it "should be 200 ok" $ do
      get "apiresp" `shouldRespondWith` 200
  context "Response with response header and cookies" $ do
    it "should be 200 ok" $ do
      get "apih" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = [ "hOut" <:> "header"
                                                                           , "Set-Cookie" <:> "cOut=cookie"
                                                                           , "Content-Type" <:> "application/json"]
                                                          , matchStatus  = 200 }
  context "Response with api error" $ do
    it "should be 500 ok" $ do
      get "apierror" `shouldRespondWith` 500
  context "Response with text as content type" $ do
    it "should be 200 ok" $ do
      get "text" `shouldRespondWith` "plaintext" { matchHeaders = ["Content-Type" <:> "text/plain;charset=utf-8"]
                                                 , matchStatus  = 200 }
  context "Response should get encoded lazily" $ do
    it "should be 200 ok" $ do
      let h = [(hAccept, "application/json")]
      request methodGet "lazyencoding" h "" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = ["Content-Type" <:> "application/json"]
                                                                                     , matchStatus  = 200 }
spec :: Spec
spec = withApp $ describe "WebApi response" $ do
  context "Simple Response" $ do
    it "should be 200 ok" $ do
      get "apiresp" `shouldRespondWith` 200
  context "Response with response header and cookies" $ do
    it "should be 200 ok" $ do
      get "apih" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = [ "hOut" <:> "header"
                                                                           , "Set-Cookie" <:> "cOut=cookie"
                                                                           , "Content-Type" <:> "application/json"]
                                                          , matchStatus  = 200 }
  context "Response with api error" $ do
    it "should be 500 ok" $ do
      get "apierror" `shouldRespondWith` 500
  context "Response with text as content type" $ do
    it "should be 200 ok" $ do
      get "text" `shouldRespondWith` "plaintext" { matchHeaders = ["Content-Type" <:> "text/plain;charset=utf-8"]
                                                 , matchStatus  = 200 }
  context "Response should get encoded lazily" $ do
    it "should be 200 ok" $ do
      let h = [(hAccept, "application/json")]
      request methodGet "lazyencoding" h "" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = ["Content-Type" <:> "application/json"]
                                                                                     , matchStatus  = 200 }
spec = withApp $ describe "WebApi response" $ do
  context "Simple Response" $ do
    it "should be 200 ok" $ do
      get "apiresp" `shouldRespondWith` 200
  context "Response with response header and cookies" $ do
    it "should be 200 ok" $ do
      get "apih" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = [ "hOut" <:> "header"
                                                                           , "Set-Cookie" <:> "cOut=cookie"
                                                                           , "Content-Type" <:> "application/json"]
                                                          , matchStatus  = 200 }
  context "Response with api error" $ do
    it "should be 500 ok" $ do
      get "apierror" `shouldRespondWith` 500
  context "Response with text as content type" $ do
    it "should be 200 ok" $ do
      get "text" `shouldRespondWith` "plaintext" { matchHeaders = ["Content-Type" <:> "text/plain;charset=utf-8"]
                                                 , matchStatus  = 200 }
  context "Response should get encoded lazily" $ do
    it "should be 200 ok" $ do
      let h = [(hAccept, "application/json")]
      request methodGet "lazyencoding" h "" `shouldRespondWith` "{\"out\":\"Done\"}" { matchHeaders = ["Content-Type" <:> "application/json"]
                                                                                     , matchStatus  = 200 }