I am trying to write a RSPEC test for my signature application using Rack :: Test. I can not understand how I can use cookies. For example, if my application sets a cookie (not through session) how can I check whether the cookie is properly set or not?
In addition, how can I send a request with that cookie?
rack :: test maintains a cookie jar which persists on requests. You can access it from Now you can test with something like this: Update: If you want to remain in test cases ( Alternatively, you can use rack_mock_session.cookies Suppose you have a handler like this:
Go '/ Cookie / Set'. Give Feedback.Setcupi "Foo" ,: Value => "Bar" end
It defines a cookie '/' rack_mock_session. Cookie_jar ["foo"]. You can access the cookies with
last_request.cookies , but as the name implies, it contains cookies for the last request. For, no answer You can set cookies with
set_cookie and clear them with
clear_cookies .
This shows how to set a cookie "What to do clear_cookies set_cookie" foo = Quux "get '/' last_request.cookies.should == {" foo "=>" Quux "} End
this block) Before performing the cases, you need to start the rack session. To do this, before your
block block
before Do: all clear_cookies end
before: each to set the necessary cookies before each request.
Comments
Post a Comment