Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Allows you to use the :session key in your tests
# (when using rack-test).
#
# get "/", {}, :session => {:user => 1}
#
class Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
def rack_test_session
@_rack_test_session ||= Session.new(app)
end
class Session < Rack::Test::Session
def env_for(path, env)
if session = env.delete(:session)
env.merge!(:cookie => "#{Rack::Utils.escape('rack.session')}=#{[Marshal.dump(session)].pack("m*")}")
end
super(path, env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment