Setting sessions in controller tests

9 views
Skip to first unread message

bertly_the_coder

unread,
Dec 4, 2014, 2:03:51 AM12/4/14
to rs...@googlegroups.com
Hi Guys,

I'm writing some tests in Rspec and one of them needs a session to be set. Does anyone know how to set a session in Rails tests?

Thanks!

Carlos Figueiredo

unread,
Dec 4, 2014, 10:26:04 AM12/4/14
to rs...@googlegroups.com
You need to set your test to run as a controller test.
A controller test have already access to session hash, and you can use wherever you want inside it

To set your tests to run as controller test you need just: 

describe MyController, type: :controller do
  before { session[:mysession] = value }

end

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/fc14d48d-4c44-48dc-97b9-a17442b25586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages