[英]Testing the state updates of a wai application
I have an application written on top of Wai , configured to have some custom state and be testable with Test.Hspec.Wai .我有一个在Wai之上编写的应用程序,配置为具有一些自定义 state 并且可以使用Test.Hspec.Wai进行测试。
I can test request/response interactions, but I haven't been able to figure out how to test for state changes;我可以测试请求/响应交互,但我无法弄清楚如何测试 state 更改; specifically, if my application state is a
TVar Text
, how do I get the value out of it inside the test, in order to verify its value?具体来说,如果我的应用程序 state 是
TVar Text
,我如何在测试中从中获取值,以验证其值?
-- app :: TVar Text -> IO Application
-- is defined in my application library
wrapp :: Text -> IO (TVar Text, Application)
wrapp s = do
s' <- newTVarIO s
a <- app s'
return (s', a)
spec :: Spec
spec = withState (wrapp "hello") $ do
describe "x" $ it "x" $ do
st <- getState -- st is TVar Text.
s <- undefined -- WHAT DO I PUT HERE TO GET THE STATE OUT OF TVar?
get "/" `shouldRespondWith` "\"hello, world!\""
s `shouldBe` "hello"
*) Note that the getState
method I'm talking about here is not exported in the latest LTS at the time of writing; *) 请注意,我这里所说的
getState
方法在撰写本文时并未在最新的 LTS 中导出; add hspec-wai-0.10.1 to extra-deps
to get a version that has all the features mentioned here.将 hspec-wai-0.10.1 添加到
extra-deps
以获得具有此处提到的所有功能的版本。
I think the problem is that you forgot to wrap whole your spec
into with app
, like it is done in hspec-wai
s README:我认为问题在于您忘记将整个
spec
包装到with app
中,就像在hspec-wai
的自述文件中所做的那样:
spec :: Spec
spec = with app $ do
describe "GET /" $ do
it "responds with 200" $ do
get "/" `shouldRespondWith` 200
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.