Fun with cookies in tests
2007-02-03
One thing’s for sure, it’s not obvious what’s going on when a test fails because of cookies. For that reason, I shied away from using cookies significantly.
Anyway, here’s a failure I was getting:
1 1) Failure: 2 test_create_session_with_right_username_and_password_and_remember_me(CreateSessionsControllerTest) 3 [test/functional/sessions_controller_test.rb:57:in `test_create_session_with_right_username_and_password_and_remember_me' 4 /home/francois/src/config/../vendor/plugins/mocha/lib/mocha/test_case_adapter.rb:19:in `run']: 5 No :auth_token cookie in the response 6 --- 7 auth_token: 8
1 1) Failure:
2 test_create_session_with_right_username_and_password_and_remember_me(CreateSessionsControllerTest)
3 [test/functional/sessions_controller_test.rb:57:in `test_create_session_with_right_username_and_password_and_remember_me’
4 /home/francois/src/config/../vendor/plugins/mocha/lib/mocha/test_case_adapter.rb:19:in `run’]:
5 No :auth_token cookie in the response
6-
7 auth_token:
8 – cookie value
Turns out the @response.cookies Hash is not indifferent. You really have to use a String to get to the content:1 def test_cookie_set 2 assert_equal ["some value"], @response.cookies["auth_token"], 3 "this will succeed" 4 assert_equal ["some value"], @response.cookies[:auth_token], 5 "this will always fail" 6 endblog comments powered by Disqus
Search
Your Host
I am François Beausoleil, a Ruby on Rails coder. During the day, I work on AdGear, an ad distribution platform for publishers. At night, I am interested many things. Read my biography.