Testing sessions using rspec

12 views
Skip to first unread message

Niv Dayan

unread,
Jun 10, 2009, 1:47:23 PM6/10/09
to sina...@googlegroups.com
Hello,

I am using Sinatra with the classic style and trying to test sessions with rspec.The 0.9.1 release notes indicated that sessions should be testible as shown in the code snippet below.

 http://groups.google.co.uk/group/sinatrarb/browse_thread/thread/7601c16ad7960cdd/c9e4043a420f4ccb?hl=en&lnk=gst&q=rspec+session#c9e4043a420f4ccb.

0.9.2 doesn't seem to indicate any changes in this area, but I saw some changes were commited on github... Could this be a regression?

My tests fail, and I'm not sure why; but it appears that the :session parameter isn't making it through the application.

I have simplified the code into the attached documents to capture the problem. The test that fails is shown again below. I would greatly appreciate any help. I am using Ruby (1.8.7), Sinatra (0.9.2), rspec (1.2.6), rack (1.0.0), rack-test (0.3.0) and mongrel (1.1.5).

 describe "Blog" do
 
  include Rack::Test::Methods

  it "should display a message if there is a session" do   
    get '/authorised_area', {}, :session => { :user => 'Niv' }
    last_response.should be_ok
  end

end
blog_sessions.rb
blog_sessions_spec.rb

Michael Jones

unread,
Jun 10, 2009, 4:40:15 PM6/10/09
to sina...@googlegroups.com
Hey

Try

{ "rack.session" =>  { :user => 'Niv' } }

Mike

<blog_sessions.rb><blog_sessions_spec.rb>

Reply all
Reply to author
Forward
0 new messages