Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3348544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:33:20+00:00 2026-05-18T01:33:20+00:00

How do I send a cookie in a functional test? How do I test

  • 0

How do I send a cookie in a functional test? How do I test to be sure that the cookie is cleared?

I’ve had great success using TDD to build the models for a Rails application, but have hit a snag with regard to controller testing: I can set cookie values once in a test and read them, but I can’t clear them. That is:

test "clears cookie" do
  get :set_it, :stuff => {'key' => 'value'} # stuff to cookify
  assert cookies['key'] == 'value' # works fine

  get :clear_it # cookie doesn't get sent. How do I simulate this?
  assert nil == cookies['key'], 'Cookie not cleared' # fails
end

The rails testing guide doesn’t mention how to simulate the sending of a cookie in a test, just how to verify that the data were set on the server. I know that I’ve run into a situation before where the cookie data is not altered on the server until the response is sent. Is that what’s happening here? I’d sorta hoped that the functional tests would have done a better job of ‘being the client.’

Is this a widely know issue? Are people just resigning themselves to using JUnit for this kind of thing? I’d really love to be able to use one framework for all or nearly all of my tdd.


Sheer desperation and guesswork led me to optimistically try @response.cookies, but that didn’t work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:33:20+00:00Added an answer on May 18, 2026 at 1:33 am

    If you want to have a unit test specifically around the unsetting of a cookie, then you’re actually testing if the response contains a header that sets the cookie to nothing. I’m assuming your get :clear_it is doing cookies.delete :cookie-name . This sets response.header to contain Set-[COOKIE-NAME]=;. So if other methods are failing, you could just look for that string directly.

    What looks fishy in your code is that you’re just checking cookies directly. Where’s the response go from your ‘get’ request?

    If all else if failing, you could also use integration tests with webrat as discussed here. This may not be as great as unit testing, but it will at least check the functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want so send every week an update by email. But Im afraid that
I am using sp_send_dbmail in SQL2005 to send an email with the results in
To send a serial string character to the serial port. I would need to
I need to send hundreds of newsletters, but would like to check first if
I need to send and receive data over serial connections (RS-232 and RS-422). How
Other than self.class.send :method, args... , of course. I'd like to make a rather
I want to send email from a Ruby application. Is there a call in
I need to send MMS thought a C# application. I have already found 2
how to send rich text message in system.net.mail need code for send a mail
If I want to send mail not via SMTP, but rather via sendmail, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.