Testing a Sinatra application that uses session

后端 未结 4 1157
粉色の甜心
粉色の甜心 2021-01-03 05:23

How to test Sinatra application which is using session?

get "/", {}, {\'rack.session\' =>  { \'foo\' => \'blah\' } }

This cod

4条回答
  •  太阳男子
    2021-01-03 06:02

    Just ran into this problem and the solution is simply the order of requiring the files, so @fguillen was correct. At the top of your spec, make sure you require rack/test before your sinatra app, so at a minimum, this should get you started:

    # in myapp_spec.rb
    require 'rspec'
    require 'rack/test'
    require 'myapp'
    
    it "should set the session params" do
      get 'users/current/projects', {}, 'rack.session' => {:user =>'1234'}
    end
    
    # in myapp.rb
    
    enable :sessions
    
    get 'users/current/projects' do
      p env['rack.session']
    end
    

提交回复
热议问题