I can''t seem to figure out how to set a cookie for a Request spec? Tried: before(:each) do @user = Fabricate(:user) request.cookies[:id_token] = @user.id end but that gives a NoMethodError errors: undefined method `cookies'' for nil:NilClass How does one run request specs when cookies need to be simulated? *Using Capybara if that matters* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120215/705bd7fc/attachment-0001.html>
David Chelimsky
2012-Feb-16 12:59 UTC
[rspec-users] How to set cookies before request spec?
On Wed, Feb 15, 2012 at 8:36 PM, Meltemi <mdemetrios at gmail.com> wrote:> I can''t seem to figure out how to set a cookie for a Request spec? ?Tried: > > before(:each) do > ??@user = Fabricate(:user) > ??request.cookies[:id_token] = @user.id > end > > but that gives a NoMethodError errors: undefined method `cookies'' for > nil:NilClass > > How does one run request specs when cookies need to be simulated? > Using Capybara if that mattersRequest specs wrap Rails'' integration tests, which simulate browser interaction, but that''s all. The idea is to not stub, simulate, etc, anything internal at all. It''s OK to create the `@user`, but cookies should get set by making other requests that do so. Make sense?
George Dinwiddie
2012-Feb-16 17:58 UTC
[rspec-users] How to set cookies before request spec?
Meltemi, On 2/15/12 9:36 PM, Meltemi wrote:> I can''t seem to figure out how to set a cookie for a Request spec? Tried: > > before(:each) do > @user = Fabricate(:user) > request.cookies[:id_token] = @user.id > end > > but that gives a NoMethodError errors: undefined method `cookies'' for > nil:NilClassIn that snippit, "request" has not been constructed and therefore is nil. - George -- ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ----------------------------------------------------------------------