nil session in integration test

20 views
Skip to first unread message

rtacconi

unread,
Aug 10, 2010, 1:27:22 PM8/10/10
to shoulda
Hi,

In this method:

should "check welcome text" do
session[:qna_user_id] = @admin.id
visit "/"
assert_contain 'Welcome to Live...'
click_link @conf_live.title
assert_contain 'Event date:'
assert_contain @conf_post.title
click_link "Management"
assert_contain 'Session starting at:'
end

I get nil class for session, why? Do you have any idea?

Curran Schiefelbein

unread,
Aug 10, 2010, 1:31:42 PM8/10/10
to sho...@googlegroups.com
What tools are you using for integration testing? If it is something
like selenium, the session will exist in the browser process, not in
your test code's context. You'll need to log the user in via the
actual web interface (visiting the login page and entering a username
and password, for instance).

Otherwise, there's not really enough information in your message to
suggest anything. Do you have other integration tests which work the
way you expect?

Curran

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com

Riccardo Tacconi

unread,
Aug 10, 2010, 2:19:05 PM8/10/10
to sho...@googlegroups.com
Hi,

Sorry I did not post enough information. I am using shoulda in unit (model) and functional testing. My app calls another app via RestClient to get the user. In functional tests I use a login_as @admin function to log in as an user. I use Factory Girl to set up the data required. In login as I just set session[:user_id] and session[:email] and it works well in functional test (with shoulda). It seems that integration tests are different and do not set the session variable, since it is nil. I saw some example of shoulda integration tests accessing directly session object, so you my app is different.

Actually this integration test, my first ever written, is using webrat in :rails mode, not selenium. Since I still do not know how I will test javascript and AJAX, I should already start to use Selenium, may be I wiil kill two birds with one stone.

Tomorrow, when I will be at work, I will post the test_helper code.
--
Riccardo Tacconi
Web developer at Wolseley UK

http://www.linkedin.com/in/riccardotacconi
http://riccardotacconi.blogspot.com/
http://twitter.com/rtacconi
Linux user: #400461

Curran Schiefelbein

unread,
Aug 10, 2010, 2:53:12 PM8/10/10
to sho...@googlegroups.com
Ok, I'm not too familiar with how the session variable works in webrat
itself (had to jump into Selenium with both feet and got soaked, you
might say). I actually posted to the webrat list with a similar
problem and never got an explanation
(http://groups.google.com/group/webrat/browse_thread/thread/435d3ac44d0d4648/ccea42b547d23ed0?lnk=gst&q=session#ccea42b547d23ed0).
But for me, it was working in :rails mode. See that link for details.

At any rate this is not a shoulda problem -- you should ask the webrat
community and see if you have better luck than I had!

Curran

Curran Schiefelbein

unread,
Aug 10, 2010, 2:55:09 PM8/10/10
to sho...@googlegroups.com
(That is to say, I think the explanation I never got was "in selenium
mode, the browser knows the session and webrat doesn't".)

Curran

Riccardo Tacconi

unread,
Aug 11, 2010, 12:02:40 PM8/11/10
to sho...@googlegroups.com
Thanks for your help.

I read some docs and I realized that in integration tests there is not a session variable available, by we have to use open_session, but I have not been able to use it.

Since I need to use Selenium, I will try to use Webrat with selenium and than I will try to access the session hash.
Reply all
Reply to author
Forward
0 new messages