Fun with cookies in tests

February 2nd, 2007

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
2
3
4
5
6
7
8
  1) Failure:
test_create_session_with_right_username_and_password_and_remember_me(CreateSessionsControllerTest)
    [test/functional/sessions_controller_test.rb:57:in `test_create_session_with_right_username_and_password_and_remember_me'
     /home/francois/src/config/../vendor/plugins/mocha/lib/mocha/test_case_adapter.rb:19:in `run']:
No :auth_token cookie in the response
---
auth_token:
- cookie value

Turns out the @response.cookies Hash is not indifferent. You really have to use a String to get to the content:

1
2
3
4
5
6
def test_cookie_set
  assert_equal ["some value"], @response.cookies["auth_token"],
    "this will succeed"
  assert_equal ["some value"], @response.cookies[:auth_token],
    "this will always fail"
end

Leave a Reply

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives