Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

Testing Cookies in Ruby on Rails

Posted by Robby Russell Mon, 28 Aug 2006 13:27:00 GMT

24 comments Latest by aaaasssss Thu, 02 Sep 2010 03:44:05 GMT

Over the weekend, Brian Ford released a useful plugin for testing your Ruby on Rails applications called, assert_cookie.

Brian likes his cookies…

“I love cookies. There are, of course, tons of varieties and I’m no connoisseur but I love the soft chocolate chip right out of the oven, hot and gooey. But, if you’re like me, you don’t want your Rails code to be gooey.” -Brian Ford

To use assert_cookie, follow these steps.

  1. Install via, script/plugin install http://svn.planetargon.org/rails/plugins/assert_cookie
  2. Fill your tests with some cookies
  3. Test your cookies!
Here are a few examples that Brian posted.
  assert_cookie :pass, 
      :value => lambda { |value| UUID.parse(value).valid? }
  assert_cookie :yellow, :value => ['sunny', 'days']
  assert_cookie :delight, :value => 'yum'
  assert_cookie :secret, :path => lambda { |path| path =~ /secret/ }, 
      :secure => true

For more information on other plugins and tools that PLANET ARGON is releasing under open source licenses, visit www.planetargon.org.

Also, be sure to subscribe to Brian Ford’s feed as he says he’ll be announcing more plugins and tips soon. :-)

Have Fun!

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Chris Blackburn Fri, 29 Dec 2006 23:44:01 GMT

    Thanks for this Brian and Robby! I use this code quite a bit.

  2. Avatar
    Matt M Thu, 03 May 2007 17:56:48 GMT

    Does this plugin work with edge rails? All of the tests pass but when I try to use the plugin I get some strange behavior.

    assert_cookie :mycookie, :value => ’’ is true all the time assert_cookie :mycookie, :value => ‘someval’ throws an error saying

    NoMethodError: undefined method `value’ for someval

  3. Avatar
    Andy Fri, 17 Oct 2008 00:54:21 GMT

    Thanks for this posting. It helped to clear things up for me when I was testing cookies in my functional tests.

    Testing cookies is a bit confusing in Rails, and I was having trouble finding that the cookies I set in the tests were not being recognized by the controller. This was because I was setting cookie[‘name’] and expecting it to be present in my get request.

    I wrote a little post here with some examples that show some of the problems I ran into and things I learned about testing cookies in Rails.

    http://qugstart.com/blog/ruby-and-rails/functional-testing-cookies-in-ruby-on-rails-123/

    Hope this helps someone else !

  4. Avatar
    ed hardy boots Thu, 18 Mar 2010 06:26:33 GMT

    This is a wonderful post,thanks.

    ed hardy boots

    ed hardy clothing

    wholesale ed hardy

  5. Avatar
    34 electric guitars Mon, 10 May 2010 03:54:42 GMT

    Three years ago the systematization music matrix used guitars for the acoustics.

  6. Avatar
    trading terms Thu, 13 May 2010 07:43:56 GMT

    the bot now responds with a subversion commit…and we made it look like ruby code! syntax colors and all!

  7. Avatar
    2010 world cup jerseys portugal Mon, 31 May 2010 07:32:56 GMT

    TYTRY TR

  8. Avatar
    2009 Collection Mon, 31 May 2010 07:33:13 GMT

    RETR

  9. Avatar
    mechanical seal Wed, 02 Jun 2010 02:43:57 GMT

    Classic exposition, I have also mentioned it in my blog article. But it is a pity that almost no friend discussed it with me. I am very happy to see your article. sankjgfbsd

  10. Avatar
    mbt black shoes Fri, 04 Jun 2010 07:50:01 GMT

    RTY TR Y

  11. Avatar
    2010 germany 16 lahm Fri, 04 Jun 2010 07:50:24 GMT

    87I9

  12. Avatar
    adidas campus Wed, 09 Jun 2010 08:53:51 GMT

    RE T

  13. Avatar
    nike max 1 Fri, 11 Jun 2010 01:35:38 GMT

    uiui

  14. Avatar
    air max 90 Sat, 12 Jun 2010 09:16:43 GMT

    tyu ty

  15. Avatar
    jordan VII Sat, 12 Jun 2010 09:16:55 GMT

    ytu

  16. Avatar
    jordan VII Sat, 12 Jun 2010 09:16:56 GMT

    ytu

  17. Avatar
    jordan VII Sun, 13 Jun 2010 08:19:05 GMT

    r6y

  18. Avatar
    asdfsdf Mon, 21 Jun 2010 04:03:47 GMT

    Thanks for this posting. It helped tchi straightenerso clear things up for me when I was testing cookies in my functional tests.

  19. Avatar
    fathers day gifts Sat, 26 Jun 2010 05:34:30 GMT

    Brilliant minds deserve our applause. You shared a very important knowledge here. Great to give as fathers day presents for techie fathers out there.

  20. Avatar
    fathers day gifts Sat, 26 Jun 2010 05:35:02 GMT

    Brilliant minds deserve our applause. You shared a very important knowledge here. Great to give as fathers day presents for techie fathers out there.

  21. Avatar
    Louis Vuitton Wallets Mon, 19 Jul 2010 17:44:17 GMT

    Louis Vuitton Joey Wallet M6658N Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M6658M Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M6658J Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M66582 Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M6658K Louis Vuitton Joey Wallet Louis Vuitton Eugenie Wallet M6388J Louis Vuitton Eugenie Wallet Louis Vuitton Eugenie Wallet M6388M Louis Vuitton Eugenie Wallet Louis Vuitton Eugenie wallet M63882 Louis Vuitton Eugenie Wallet Louis Vuitton Eugenie wallet M6388K Louis Vuitton Eugenie Wallet Louis Vuitton Astrid Wallet M6659N Louis Vuitton Astrid Wallet Louis Vuitton Astrid Wallet M6659K Louis Vuitton Astrid Wallet Louis Vuitton Astrid Wallet M6659J Louis Vuitton Astrid Wallet Louis Vuitton Astrid Wallet M66592 Louis Vuitton Astrid Wallet

  22. Avatar
    http://www.bestretroshoes.com Tue, 10 Aug 2010 09:46:24 GMT
    Air Max 2003,Air Max 2003
    Aix Max Plus Tn,Aix Max Plus Tn
    Nike Jordan 15,Nike Jordan 15
    Jordan 11 Sharkley,Jordan 11 Sharkley
    Jordan Portfolio 2010,Jordan Portfolio 2010
    Nike Air Jordan 25,Nike Air Jordan 25
    jordans 3,jordans 3
    jordans 4,jordans 4
    air jordans 19,air jordans 19
  23. Avatar
    replica watches Mon, 30 Aug 2010 08:30:19 GMT
  24. Avatar
    aaaasssss Thu, 02 Sep 2010 03:44:05 GMT

Share your thoughts... (really...I want to hear them)

Comments