Skip to content

Instantly share code, notes, and snippets.

@ambethia
Forked from djanowski/test_helper.rb
Created September 4, 2009 11:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ambethia/180848 to your computer and use it in GitHub Desktop.
# 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