Permalink
Browse files

get_me_the_cookie should return nil if the cookie doesn't exist.

I'm adding a test and a fix for rack-test.
  • Loading branch information...
1 parent 026415c commit cf482023c3c64e2f6c777c0a576d98897277fb6f @jordanstephens jordanstephens committed Jul 19, 2012
Showing with 6 additions and 1 deletion.
  1. +2 −1 lib/show_me_the_cookies/rack_test.rb
  2. +4 −0 spec/shared_examples_for_api.rb
View
3 lib/show_me_the_cookies/rack_test.rb
@@ -4,7 +4,8 @@ def initialize(rack_test_driver)
end
def get_me_the_cookie(cookie_name)
- _translate_cookie cookies.select {|c| c.name == cookie_name}.first
+ found = cookies.select {|c| c.name == cookie_name}
+ found.empty? ? nil : _translate_cookie(found.first)
end
def get_me_the_cookies
View
4 spec/shared_examples_for_api.rb
@@ -21,6 +21,10 @@ def cookies_should_not_contain(key, value)
end
end
+ it "returns nil for cookies that do not exist" do
+ get_me_the_cookie('some_unset_cookie').should be_nil
+ end
+
describe "get_me_the_cookies" do
it "returns an array of standardised cookie hashes" do
visit '/set/foo/bar'

0 comments on commit cf48202

Please sign in to comment.