Permalink
Browse files

Adding session hash support to specs

  • Loading branch information...
1 parent af52196 commit 43e4846ebf4552ba5ff7fc634a279474c453b4ef @guilleiguaran guilleiguaran committed Dec 6, 2010
Showing with 30 additions and 1 deletion.
  1. +30 −1 specs/spec_helper.rb
View
@@ -17,4 +17,33 @@
set :environment, :test
set :run, false
set :raise_errors, true
-set :logging, false
+set :logging, false
+
+class SessionData
+ def initialize(cookies)
+ @cookies = cookies
+ @data = cookies['rack.session']
+ if @data
+ @data = @data.unpack("m*").first
+ @data = Marshal.load(@data)
+ else
+ @data = {}
+ end
+ end
+
+ def [](key)
+ @data[key]
+ end
+
+ def []=(key, value)
+ @data[key] = value
+ session_data = Marshal.dump(@data)
+ session_data = [session_data].pack("m*")
+ @cookies.merge("rack.session=#{Rack::Utils.escape(session_data)}", URI.parse("//example.org//"))
+ raise "session variable not set" unless @cookies['rack.session'] == session_data
+ end
+end
+
+def session
+ SessionData.new(rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar)
+end

0 comments on commit 43e4846

Please sign in to comment.