I have an application written on top of Wai, configured to have some custom state and be testable with Test.Hspec.Wai.
I can test request/response interactions, but I haven't been able to figure out how to test for state changes; 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?
-- 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; add hspec-wai-0.10.1 to extra-deps
to get a version that has all the features mentioned here.
I think the problem is that you forgot to wrap whole your
spec
intowith app
, like it is done inhspec-wai
s README: