Forum: Ruby on Rails problem with cookies in tests (TDD)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Benjamin Kuz (Guest)
on 2006-01-11 00:12
The problem I'm having is that I can't seem to destroy the cookies and
assert that they were indeed destroyed inside the test.
The code to do this does work - the cookies are created, and are
destroyed when this is done in a browser, but I can't seem to make the
test pass.


  def test_should_pass_if_logout_destroys_cookie_data
    post :login, { :user => { :login => 'ben', :password => 'password'
}, :remember => 1 }
    assert_equal(User.hash_password('password'), cookies["password"][0])
    assert_equal('ben', cookies["login"][0])
    get :logout
    assert_nil cookies["password"][0]
    assert_nil cookies["login"][0]


  def logout
    session['user'] = nil
    cookies.delete :login if cookies[:login]
    cookies.delete :password if cookies[:password]

rake test failure (assert_nil cookies["password"][0] is what fails):

  1) Failure:
<nil> expected but was


Thanks in advance,

Benjamin Kuz
Bravenet Web Services
This topic is locked and can not be replied to.