1313 before :each do
1414 @session = double "servlet session"
1515 @request = double "servlet request"
16- @options = { "java_servlet_request" => @request }
16+ @options = { "java_servlet_request" => @request }
1717 end
1818
1919 def session_store
@@ -29,47 +29,47 @@ def session_store
2929
3030 describe "#restore" do
3131 it "should do nothing if no session established" do
32- @request . should_receive ( :getSession ) . and_return nil
33- session_store . restore . should == { }
32+ expect ( @request ) . to receive ( :getSession ) . and_return nil
33+ expect ( session_store . restore ) . to eq ( { } )
3434 end
3535
3636 it "should do nothing if the session does not have anything in it" do
37- @request . should_receive ( :getSession ) . with ( false ) . and_return @session
38- @session . should_receive ( :getAttributeNames ) . and_return [ ]
39- session_store . restore . should == { }
37+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return @session
38+ expect ( @session ) . to receive ( :getAttributeNames ) . and_return [ ]
39+ expect ( session_store . restore ) . to eq ( { } )
4040 end
4141
4242 it "should retrieve the marshalled session from the java session" do
43- hash = { "foo" => 1 , "bar" => true }
43+ hash = { "foo" => 1 , "bar" => true }
4444 marshal_data = Marshal . dump hash
45- @request . should_receive ( :getSession ) . with ( false ) . and_return @session
46- @session . should_receive ( :getAttributeNames ) . and_return (
45+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return @session
46+ expect ( @session ) . to receive ( :getAttributeNames ) . and_return (
4747 [ CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY ] )
48- @session . should_receive ( :getAttribute ) . with (
48+ expect ( @session ) . to receive ( :getAttribute ) . with (
4949 CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY ) . and_return marshal_data . to_java_bytes
50- session_store . restore . should == hash
50+ expect ( session_store . restore ) . to eq hash
5151 end
5252
5353 it "should retrieve values from other keys in the session" do
54- hash = { "foo" => 1 , "bar" => true }
55- @request . should_receive ( :getSession ) . with ( false ) . and_return @session
56- @session . should_receive ( :getAttributeNames ) . and_return [ "foo" , "bar" ]
57- @session . should_receive ( :getAttribute ) . with ( "foo" ) . and_return hash [ "foo" ]
58- @session . should_receive ( :getAttribute ) . with ( "bar" ) . and_return hash [ "bar" ]
59- session_store . restore . should == hash
54+ hash = { "foo" => 1 , "bar" => true }
55+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return @session
56+ expect ( @session ) . to receive ( :getAttributeNames ) . and_return [ "foo" , "bar" ]
57+ expect ( @session ) . to receive ( :getAttribute ) . with ( "foo" ) . and_return hash [ "foo" ]
58+ expect ( @session ) . to receive ( :getAttribute ) . with ( "bar" ) . and_return hash [ "bar" ]
59+ expect ( session_store . restore ) . to eq hash
6060 end
6161
6262 it "should retrieve java objects in the session" do
63- @request . should_receive ( :getSession ) . with ( false ) . and_return @session
64- @session . should_receive ( :getAttributeNames ) . and_return [ "foo" ]
65- @session . should_receive ( :getAttribute ) . with ( "foo" ) . and_return java . lang . Object . new
66- session_store . restore [ "foo" ] . should be_instance_of ( java . lang . Object )
63+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return @session
64+ expect ( @session ) . to receive ( :getAttributeNames ) . and_return [ "foo" ]
65+ expect ( @session ) . to receive ( :getAttribute ) . with ( "foo" ) . and_return java . lang . Object . new
66+ expect ( session_store . restore [ "foo" ] ) . to be_instance_of ( java . lang . Object )
6767 end
6868 end
6969
7070 describe "#update" do
7171 before :each do
72- @request . should_receive ( :getSession ) . with ( true ) . and_return @session
72+ expect ( @request ) . to receive ( :getSession ) . with ( true ) . and_return @session
7373 end
7474
7575 it "should do nothing if the session data is empty" do
@@ -79,26 +79,26 @@ def session_store
7979 end
8080
8181 it "should marshal the session to the java session" do
82- @session . should_receive ( :setAttribute ) . with (
82+ expect ( @session ) . to receive ( :setAttribute ) . with (
8383 CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY ,
8484 an_instance_of ( Java ::byte [ ] ) )
8585 session_store . update
8686 end
8787
8888 it "should store entries with string keys and values as java session attributes" do
89- @session . should_receive ( :setAttribute ) . with (
89+ expect ( @session ) . to receive ( :setAttribute ) . with (
9090 CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY , anything )
91- @session . should_receive ( :setAttribute ) . with ( "foo" , "bar" )
91+ expect ( @session ) . to receive ( :setAttribute ) . with ( "foo" , "bar" )
9292 store = session_store
9393 store . data [ "foo" ] = "bar"
9494 store . update
9595 end
9696
9797 it "should store numeric, nil, or boolean values as java session attributes" do
98- @session . should_receive ( :setAttribute ) . with ( "foo" , true )
99- @session . should_receive ( :setAttribute ) . with ( "bar" , 20 )
100- @session . should_receive ( :setAttribute ) . with ( "baz" , nil )
101- @session . should_receive ( :setAttribute ) . with ( "quux" , false )
98+ expect ( @session ) . to receive ( :setAttribute ) . with ( "foo" , true )
99+ expect ( @session ) . to receive ( :setAttribute ) . with ( "bar" , 20 )
100+ expect ( @session ) . to receive ( :setAttribute ) . with ( "baz" , nil )
101+ expect ( @session ) . to receive ( :setAttribute ) . with ( "quux" , false )
102102 store = session_store
103103 store . data . clear
104104 store . data [ "foo" ] = true
@@ -109,15 +109,15 @@ def session_store
109109 end
110110
111111 it "should store java object values as java session attributes" do
112- @session . should_receive ( :setAttribute ) . with ( "foo" , an_instance_of ( java . lang . Object ) )
112+ expect ( @session ) . to receive ( :setAttribute ) . with ( "foo" , an_instance_of ( java . lang . Object ) )
113113 store = session_store
114114 store . data . clear
115115 store . data [ "foo" ] = java . lang . Object . new
116116 store . update
117117 end
118118
119119 it "should not store entries with non-primitive values in the java session" do
120- @session . should_receive ( :setAttribute ) . with (
120+ expect ( @session ) . to receive ( :setAttribute ) . with (
121121 CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY , anything )
122122 store = session_store
123123 store . data [ "foo" ] = Object . new
@@ -128,8 +128,8 @@ def session_store
128128
129129 describe "#close" do
130130 it "should do the same as update" do
131- @request . should_receive ( :getSession ) . with ( true ) . and_return @session
132- @session . should_receive ( :setAttribute ) . with (
131+ expect ( @request ) . to receive ( :getSession ) . with ( true ) . and_return @session
132+ expect ( @session ) . to receive ( :setAttribute ) . with (
133133 CGI ::Session ::JavaServletStore ::RAILS_SESSION_KEY ,
134134 an_instance_of ( Java ::byte [ ] ) )
135135 session_store . close
@@ -138,20 +138,20 @@ def session_store
138138
139139 describe "#delete" do
140140 it "should invalidate the servlet session" do
141- @request . should_receive ( :getSession ) . with ( false ) . and_return @session
142- @session . should_receive ( :invalidate )
141+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return @session
142+ expect ( @session ) . to receive ( :invalidate )
143143 session_store . delete
144144 end
145145
146146 it "should do nothing if no session is established" do
147- @request . should_receive ( :getSession ) . with ( false ) . and_return nil
147+ expect ( @request ) . to receive ( :getSession ) . with ( false ) . and_return nil
148148 session_store . delete
149149 end
150150 end
151151
152152 describe "#generate_digest" do
153153 before :each do
154- @request . should_receive ( :getSession ) . with ( true ) . and_return @session
154+ expect ( @request ) . to receive ( :getSession ) . with ( true ) . and_return @session
155155 @dbman = session_store
156156 end
157157
@@ -160,17 +160,17 @@ def hmac(key, data)
160160 end
161161
162162 it "should look for the secret in the java session" do
163- @session . should_receive ( :getAttribute ) . with ( "__rails_secret" ) . and_return "secret"
164- @dbman . generate_digest ( "key" ) . should == hmac ( "secret" , "key" )
163+ expect ( @session ) . to receive ( :getAttribute ) . with ( "__rails_secret" ) . and_return "secret"
164+ expect ( @dbman . generate_digest ( "key" ) ) . to eq ( hmac ( "secret" , "key" ) )
165165 end
166166
167167 it "should generate a secret from the java session id and last accessed time" do
168- OpenSSL ::Random . should_receive ( :random_bytes ) . with ( 32 ) . and_return "random"
169- @session . should_receive ( :getAttribute ) . with ( "__rails_secret" ) . and_return nil
170- @session . should_receive ( :getId ) . and_return "abc"
171- @session . should_receive ( :getLastAccessedTime ) . and_return 123
172- @session . should_receive ( :setAttribute ) . with ( "__rails_secret" , "abcrandom123" )
173- @dbman . generate_digest ( "key" ) . should == hmac ( "abcrandom123" , "key" )
168+ expect ( OpenSSL ::Random ) . to receive ( :random_bytes ) . with ( 32 ) . and_return "random"
169+ expect ( @session ) . to receive ( :getAttribute ) . with ( "__rails_secret" ) . and_return nil
170+ expect ( @session ) . to receive ( :getId ) . and_return "abc"
171+ expect ( @session ) . to receive ( :getLastAccessedTime ) . and_return 123
172+ expect ( @session ) . to receive ( :setAttribute ) . with ( "__rails_secret" , "abcrandom123" )
173+ expect ( @dbman . generate_digest ( "key" ) ) . to eq ( hmac ( "abcrandom123" , "key" ) )
174174 end unless JRUBY_VERSION < '1.7.0'
175175 end
176176end
0 commit comments