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</span>.cookies[<span class="s"><span class="dl">&quot;</span><span class="k">auth_token</span><span class="dl">&quot;</span></span>], <span class="no">3</span> <span class="s"><span class="dl">&quot;</span><span class="k">this will succeed</span><span class="dl">&quot;</span></span> <span class="no">4</span> assert_equal [<span class="s"><span class="dl">&quot;</span><span class="k">some value</span><span class="dl">&quot;</span></span>], <span class="iv">response.cookies[:auth_token],
5 "this will always fail"
6 end

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on