How to test that session[:message] is used?

26 views
Skip to first unread message

Tsvetelina Borisova

unread,
Jul 8, 2012, 6:05:33 PM7/8/12
to rs...@googlegroups.com
Hello, I have this situation: I have one controller - Notifier that puts message in session[:message] and I have other controller - SendQueues that uses this value in session[:message] and gives it to a method of a class. Now I don't know how to test that the controller - SendQueues gives to the class the value of the session[;message] and not other value. Can you give me an advice? Thanks in advance :)

David Chelimsky

unread,
Jul 9, 2012, 9:07:40 AM7/9/12
to rs...@googlegroups.com
The fact that NotfierController sets the message is not relevant to an
isolated example of the behavior of SendQueuesController. In a
controller spec, you have access to the session before the the action
is invoked, so:

describe SendQueuesController do
describe "GET #some_action" do
it "passes session[:message] to SomeClass" do
session[:message] = "session message"
SomeClass.should_receive(:some_message).with("session message")
get :some_action
end
end
end

HTH,
David

PS - it's generally better to post code snippets than describe the
code. My response is filled with assumptions that may or may not be
correct, and working against a code snippet would reduce the amount of
guessing.

Tsvetelina Borisova

unread,
Jul 9, 2012, 9:19:13 AM7/9/12
to rs...@googlegroups.com
Thanks for the quick and helpful response David :) . And yes for the code snippets I forgot about them :)


--
You received this message because you are subscribed to the Google Groups "rspec" group.
To post to this group, send email to rs...@googlegroups.com.
To unsubscribe from this group, send email to rspec+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rspec?hl=en.


Reply all
Reply to author
Forward
0 new messages