-
-
Save ambethia/180848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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