Created
April 1, 2011 04:19
-
-
Save jmccartie/897722 to your computer and use it in GitHub Desktop.
simple helper with cookie and it's test that won't work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper | |
# Set first_time? cookie | |
def set_first_time_cookie | |
cookies[:first_time] = { | |
:value => 'false', | |
:expires => 30.years.from_now, | |
} | |
end | |
# spec | |
describe "set_first_time_cookie" do | |
it "sets the cookie" do | |
helper.set_first_time_cookie() | |
helper.request.cookies[:first_time].should == "false" | |
end | |
end | |
# Result | |
# expected: "false" | |
# got: nil (using ==) | |
# also, helper.request.cookies = {} |
Sorry - wrote that in a hurry. Updated, but still the same result. Appreciate you taking a look.
I not sure if this is the way to test cookies. In my specs, I am testing a controller, so I can actually issue a 'GET' request.
it "sets the given email in a cookie for later use" do
get "subscribe", :module_id => 1, :subscription => {:title => @title, :email => @email}
cookies[:email].should ==@email
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is set_first_time_cookie actually called somewhere?