Helper Method
# Determine if this is user's first time
def first_time?
cookies[:first_time].nil?
end
Attempted Rspec test
it "returns true if the cookie is set" do
cookies[:first_time] = "something"
helper.first_time?().should be(true)
end
Error:
undefined method `cookies' for nil:NilClass
Everything I've read about Rspec and cookies has to do with the controller. Any way to get/set cookies in Rspec helper tests?
(Rspec/Rspec-rails 2.5, Rails 3.0.4)
Thanks!!
UPDATE:
Found an answer on how to SET cookies, so I'll leave it here for other's reference.
the piece I was looking for:
helper.request.cookies[:awesome] = "something"
Still don't know how to GET cookies...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…