Ah, you're right. I've switched those asserts around.
I am mostly writing my tests in RSpec, with RSpec-Rails, at the moment. Their documentation recommends using cookies over response.cookies and that's worked for me so far.
While writing this up, it was confusing what the difference between cookies and response.cookies is within the minitest versions. I might have to dig into that further to work out exactly what is going on.
Alright! I'm currently in the process of refactoring some tests using minitest (with Rails), will let you know what would potentially work for me (hopefully).
I've spelunked the rails code source, #cookies in minitest always refers to the request's cookies ( even after the HTTP call), and is a Rack::Test::CookieJar instance, whereas response.cookies is a plain ruby hash containing the responses's cookies. I'm going to instantiate a rails Cookie Jar as suggested in your article, but using response.cookies as the second argument.
We would need to use response.cookies. No need to add .to_hash because response.cookies is already a hash.
Unlike Rspec, cookies in Minitest ( or Rails custom version of minitest) always refer to the request cookies which is an instance of Rack::Test::CookieJar
Ah, you're right. I've switched those asserts around.
I am mostly writing my tests in RSpec, with RSpec-Rails, at the moment. Their documentation recommends using
cookies
overresponse.cookies
and that's worked for me so far.While writing this up, it was confusing what the difference between
cookies
andresponse.cookies
is within the minitest versions. I might have to dig into that further to work out exactly what is going on.Alright! I'm currently in the process of refactoring some tests using minitest (with Rails), will let you know what would potentially work for me (hopefully).
I've spelunked the rails code source,
#cookies
in minitest always refers to the request's cookies ( even after the HTTP call), and is aRack::Test::CookieJar
instance, whereasresponse.cookies
is a plain ruby hash containing the responses's cookies. I'm going to instantiate a rails Cookie Jar as suggested in your article, but usingresponse.cookies
as the second argument.Update: I've figured out how to make it work in my tests ( was having weird issues but application related, not rails related)
Basically to make this work in Rails/minitest, one would do:
We would need to use
response.cookies
. No need to add.to_hash
because response.cookies is already a hash.Unlike Rspec,
cookies
in Minitest ( or Rails custom version of minitest) always refer to the request cookies which is an instance ofRack::Test::CookieJar
This is the answer I have been looking for. I had originally used
But realised late on that the cookies.to_hash was empty as I never set cookies in Rack::Test::CookieJar
Thank you for this