Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created April 1, 2011 04:19
Show Gist options
  • Save jmccartie/897722 to your computer and use it in GitHub Desktop.
Save jmccartie/897722 to your computer and use it in GitHub Desktop.
simple helper with cookie and it's test that won't work
# 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 = {}
@jhwist
Copy link

jhwist commented Apr 1, 2011

Is set_first_time_cookie actually called somewhere?

@jmccartie
Copy link
Author

Sorry - wrote that in a hurry. Updated, but still the same result. Appreciate you taking a look.

@jhwist
Copy link

jhwist commented Apr 4, 2011

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