Testing Cookies in Ruby on Rails
4 comments Latest by ed hardy boots Thu, 18 Mar 2010 06:26:33 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.
- Install via,
script/plugin install http://svn.planetargon.org/rails/plugins/assert_cookie - Fill your tests with some cookies
- Test your cookies!
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 => trueFor 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!
Enjoying the content? Be sure to subscribe to my RSS feed.






Thanks for this Brian and Robby! I use this code quite a bit.
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
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 !
This is a wonderful post,thanks.
ed hardy boots
ed hardy clothing
wholesale ed hardy