Skip to content

Commit ba22ea9

Browse files
committed
Correct rspec expectations
Signed-off-by: Chad Wilson <[email protected]>
1 parent e4a4eee commit ba22ea9

12 files changed

+117
-127
lines changed

src/spec/ruby/action_controller/session/java_servlet_store_spec.rb

+22-22
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
end
3434

3535
it "should raise an error if the servlet request is not present" do
36-
lambda { @session_store.call({}) }.should raise_error
36+
expect { @session_store.call({}) }.to raise_error(RuntimeError)
3737
end
3838

3939
it "should do nothing if the session is not accessed" do
@@ -57,7 +57,7 @@
5757
it "should load the session when accessed" do
5858
@request.should_receive(:getSession).with(false).and_return @session
5959
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
60-
@app.should_receive(:call).and_return do |env|
60+
@app.should_receive(:call) do |env|
6161
env['rack.session']['foo']
6262
end
6363
@session_store.call(@env)
@@ -73,7 +73,7 @@
7373
it "should report session loaded when accessed" do
7474
@request.should_receive(:getSession).with(false).and_return @session
7575
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
76-
@app.should_receive(:call).and_return do |env|
76+
@app.should_receive(:call) do |env|
7777
env['rack.session']['foo']
7878
end
7979
@session_store.call(@env)
@@ -84,7 +84,7 @@
8484
it "should use custom session hash when loading session" do
8585
@request.should_receive(:getSession).with(false).and_return @session
8686
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
87-
@app.should_receive(:call).and_return do |env|
87+
@app.should_receive(:call) do |env|
8888
env['rack.session']["foo"] = "bar"
8989
end
9090
@session_store.call(@env)
@@ -106,7 +106,7 @@
106106
@session.should_receive(:getAttributeNames).and_return [session_key]
107107
@session.should_receive(:getAttribute).with(session_key).and_return marshal_data.to_java_bytes
108108
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
109-
@app.should_receive(:call).and_return do |env|
109+
@app.should_receive(:call) do |env|
110110
env['rack.session']["foo"].should == 1
111111
env['rack.session']["bar"].should == true
112112
end
@@ -120,7 +120,7 @@
120120
@session.should_receive(:getAttribute).with("foo").and_return hash["foo"]
121121
@session.should_receive(:getAttribute).with("bar").and_return hash["bar"]
122122
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
123-
@app.should_receive(:call).and_return do |env|
123+
@app.should_receive(:call) do |env|
124124
env['rack.session']["foo"].should == hash["foo"]
125125
env['rack.session']["bar"].should == hash["bar"]
126126
end
@@ -132,7 +132,7 @@
132132
@session.should_receive(:getAttributeNames).and_return ["foo"]
133133
@session.should_receive(:getAttribute).with("foo").and_return java.lang.Object.new
134134
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
135-
@app.should_receive(:call).and_return do |env|
135+
@app.should_receive(:call) do |env|
136136
env['rack.session']["foo"].should be_kind_of(java.lang.Object)
137137
end
138138
@session_store.call(@env)
@@ -143,7 +143,7 @@
143143
@session.stub(:getAttribute).and_return nil; @session.stub(:getCreationTime).and_return 1
144144
@session.should_receive(:setAttribute).with(ActionController::Session::JavaServletStore::RAILS_SESSION_KEY,
145145
an_instance_of(Java::byte[]))
146-
@app.should_receive(:call).and_return do |env|
146+
@app.should_receive(:call) do |env|
147147
env['rack.session']['foo'] = Object.new
148148
end
149149
@session_store.call(@env)
@@ -154,7 +154,7 @@
154154
@request.should_receive(:getSession).with(true).ordered.and_return @session
155155
@session.should_receive(:setAttribute).with(ActionController::Session::JavaServletStore::RAILS_SESSION_KEY,
156156
an_instance_of(Java::byte[]))
157-
@app.should_receive(:call).and_return do |env|
157+
@app.should_receive(:call) do |env|
158158
env['rack.session']['foo'] = Object.new
159159
end
160160
@session_store.call(@env)
@@ -164,7 +164,7 @@
164164
@request.should_receive(:getSession).with(false).and_return @session
165165
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
166166
@session.should_receive(:setAttribute).with("foo", "bar")
167-
@app.should_receive(:call).and_return do |env|
167+
@app.should_receive(:call) do |env|
168168
env['rack.session']["foo"] = "bar"
169169
end
170170
@session_store.call(@env)
@@ -176,7 +176,7 @@
176176
@session.should_receive(:setAttribute).with("foo", true)
177177
@session.should_receive(:setAttribute).with("bar", 20)
178178
@session.should_receive(:setAttribute).with("baz", false)
179-
@app.should_receive(:call).and_return do |env|
179+
@app.should_receive(:call) do |env|
180180
env['rack.session']["foo"] = true
181181
env['rack.session']["bar"] = 20
182182
env['rack.session']["baz"] = false
@@ -188,7 +188,7 @@
188188
@request.should_receive(:getSession).with(false).and_return @session
189189
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
190190
@session.should_receive(:setAttribute).with("foo", an_instance_of(java.lang.Object))
191-
@app.should_receive(:call).and_return do |env|
191+
@app.should_receive(:call) do |env|
192192
env['rack.session']["foo"] = java.lang.Object.new
193193
end
194194
@session_store.call(@env)
@@ -200,7 +200,7 @@
200200
@session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1
201201
@session.should_receive(:removeAttribute).with("foo")
202202
@session.should_receive(:removeAttribute).with("baz")
203-
@app.should_receive(:call).and_return do |env|
203+
@app.should_receive(:call) do |env|
204204
env['rack.session'].delete('foo')
205205
env['rack.session']['baz'] = nil
206206
env['rack.session']['bar'] = 'x'
@@ -212,7 +212,7 @@
212212
@request.should_receive(:getSession).with(false).and_return @session
213213
@session.stub(:getId).and_return(nil)
214214
@session.should_receive(:invalidate).ordered
215-
@app.should_receive(:call).and_return do |env|
215+
@app.should_receive(:call) do |env|
216216
env['rack.session.options'].delete(:id)
217217
#env['rack.session'] = new_session_hash(env)
218218
env['rack.session'].send :load!
@@ -224,11 +224,11 @@
224224
session = double_http_session(nil); session.invalidate
225225
@request.should_receive(:getSession).with(false).and_return session
226226

227-
@app.should_receive(:call).and_return do |env|
227+
@app.should_receive(:call) do |env|
228228
env['rack.session.options'].delete(:id)
229229
env['rack.session'].send :load!
230230
end
231-
expect( lambda { @session_store.call(@env) } ).to_not raise_error
231+
expect { @session_store.call(@env) }.to_not raise_error
232232
end
233233

234234
it "should handle session with an invalid servlet session" do
@@ -240,15 +240,15 @@
240240
@request.should_receive(:getSession).ordered.
241241
with(true).and_return new_session = double_http_session
242242

243-
@app.should_receive(:call).and_return do |env|
243+
@app.should_receive(:call) do |env|
244244
env['rack.session']['foo'] = 'bar'
245245
end
246246
@session_store.call(@env)
247247
end
248248

249249
it "should do nothing on session reset if no session is established" do
250250
@request.should_receive(:getSession).with(false).and_return nil
251-
@app.should_receive(:call).and_return do |env|
251+
@app.should_receive(:call) do |env|
252252
env['rack.session.options'].delete(:id)
253253
env['rack.session'] = new_session_hash(env) # not loaded?
254254
end
@@ -260,7 +260,7 @@
260260
@request.should_receive(:getSession).and_return @session
261261
@session.should_receive(:getLastAccessedTime).and_return time
262262
@session.stub(:setAttribute)
263-
@app.should_receive(:call).and_return do |env|
263+
@app.should_receive(:call) do |env|
264264
env['rack.session'].getLastAccessedTime.should == time
265265
lambda { env['rack.session'].blah_blah }.should raise_error(NoMethodError)
266266
end
@@ -274,7 +274,7 @@
274274
new_session = double_http_session
275275
@request.should_receive(:getSession).ordered.with(true).and_return(new_session)
276276

277-
@app.should_receive(:call).and_return do |env|
277+
@app.should_receive(:call) do |env|
278278
env['rack.session.options'] = { :id => sid, :renew => true, :defer => true }
279279
env['rack.session']['_csrf_token'] = 'v3PrzsdkWug9Q3xCthKkEzUMbZSzgQ9Bt+43lH0bEF8='
280280
end
@@ -292,11 +292,11 @@
292292
it "handles the skip session option" do
293293
@request.should_receive(:getSession).with(false).and_return @session
294294
@session.should_not_receive(:setAttribute)
295-
@app.should_receive(:call).and_return do |env|
295+
@app.should_receive(:call) do |env|
296296
env['rack.session.options'][:skip] = true
297297
env['rack.session']['foo'] = 'bar'
298298
end
299-
expect( lambda { @session_store.call(@env) } ).to_not raise_error
299+
expect { @session_store.call(@env) }.to_not raise_error
300300
end
301301

302302
private

src/spec/ruby/cgi/session/java_servlet_store_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def session_store
2424

2525
it "should raise an error if the servlet request is not present" do
2626
@options.delete("java_servlet_request")
27-
lambda { session_store }.should raise_error
27+
expect { session_store }.to raise_error(RuntimeError)
2828
end
2929

3030
describe "#restore" do

src/spec/ruby/jruby/rack/helpers_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SomeKlass < Object
4444
end
4545

4646
it "constantizes strictly" do
47-
expect( lambda { constantize('Some', A::B) } ).to raise_error(NameError)
47+
expect { constantize('Some', A::B) }.to raise_error(NameError)
4848
end
4949

5050
it "constantizes non-stricly from Object (parent) context" do
@@ -95,8 +95,8 @@ class SomeKlass < Object
9595

9696
it "resolves a constant" do
9797
expect( resolve_constant("JRuby::Rack::Helpers::Some") ).to be_a Class
98-
expect( lambda { resolve_constant("JRuby::Rack::Helpers::Missing") }).to raise_error NameError
99-
expect( lambda { resolve_constant("JRuby::Rack::Helpers::Another") }).to raise_error NameError
98+
expect { resolve_constant("JRuby::Rack::Helpers::Missing") }.to raise_error NameError
99+
expect { resolve_constant("JRuby::Rack::Helpers::Another") }.to raise_error NameError
100100
end
101101

102102
end

src/spec/ruby/jruby/rack/queues_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ def mock_message(text)
108108
@registry.register_listener "FooQ", listener
109109
@queue_manager.should_receive(:close).with "FooQ"
110110
@registry.unregister_listener(listener)
111-
lambda { @registry.receive_message("FooQ", mock_message("msg")) }.should raise_error
111+
lambda { @registry.receive_message("FooQ", mock_message("msg")) }.should raise_error(RuntimeError)
112112
end
113113

114114
it "#receive_message should raise an exception if there is no listener for the queue" do
115-
lambda { @registry.receive_message("NoQ", "hi") }.should raise_error
115+
lambda { @registry.receive_message("NoQ", "hi") }.should raise_error(RuntimeError)
116116
end
117117

118118
it "#register_listener should allow multiple listeners per queue" do
@@ -175,7 +175,7 @@ def mock_message(text)
175175
it "should unmarshal the message if the marshal payload property is set" do
176176
@message.should_receive(:getBooleanProperty).with(JRuby::Rack::Queues::MARSHAL_PAYLOAD).and_return true
177177
first = false
178-
@message.should_receive(:readBytes).twice.and_return do |byte_array|
178+
@message.should_receive(:readBytes).twice do |byte_array|
179179
if first
180180
-1
181181
else
@@ -233,13 +233,13 @@ def on_message(msg)
233233
@servlet_context.should_receive(:log).with(/something went wrong/)
234234
lambda do
235235
JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
236-
end.should raise_error
236+
end.should raise_error(RuntimeError)
237237
end
238238

239239
it "should raise an exception if it was unable to dispatch to anything" do
240240
@message.stub(:getBooleanProperty).and_return false
241241
lambda do
242242
JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message)
243-
end.should raise_error
243+
end.should raise_error(RuntimeError)
244244
end
245245
end

src/spec/ruby/jruby/rack/response_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class << value; undef_method :each; end if value.respond_to?(:each)
181181
response.write_headers(response_environment)
182182

183183
times = 0
184-
stream.should_receive(:write).exactly(6).times.with do |bytes|
184+
stream.should_receive(:write).exactly(6).times do |bytes|
185185
str = String.from_java_bytes(bytes)
186186
str = str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
187187
case times += 1
@@ -223,7 +223,7 @@ class << value; undef_method :each; end if value.respond_to?(:each)
223223
response.write_headers(response_environment)
224224

225225
times = 0
226-
stream.should_receive(:write).exactly(3).times.with do |bytes|
226+
stream.should_receive(:write).exactly(3).times do |bytes|
227227
str = String.from_java_bytes(bytes)
228228
case times += 1
229229
when 1 then str.should == "1\r\n1\r\n"
@@ -258,7 +258,7 @@ class << value; undef_method :each; end if value.respond_to?(:each)
258258
response.write_headers(response_environment)
259259

260260
times = 0
261-
stream.should_receive(:write).exactly(5).times.with do |bytes|
261+
stream.should_receive(:write).exactly(5).times do |bytes|
262262
str = String.from_java_bytes(bytes)
263263
case times += 1
264264
when 1 then str.should == "1"
@@ -404,7 +404,7 @@ def wrap_file_body(path) # Rails style when doing #send_file
404404
path = File.expand_path('../../files/image.jpg', File.dirname(__FILE__))
405405

406406
response = JRuby::Rack::Response.new [ 200, {}, FileBody.new(path) ]
407-
response.should_receive(:send_file).with do |path, response|
407+
response.should_receive(:send_file) do |path, response|
408408
expect( path ).to eql path
409409
expect( response).to be response_environment
410410
end
@@ -526,13 +526,13 @@ def with_swallow_client_abort(client_abort = true)
526526

527527
private
528528

529-
def update_response_headers(headers, response)
529+
def update_response_headers(headers)
530530
response.to_java.getHeaders.update(headers)
531531
end
532532

533-
def new_response_environment(servlet_response)
533+
def new_response_environment(this_servlet_response = servlet_response)
534534
org.jruby.rack.RackResponseEnvironment.impl do |name, *args|
535-
servlet_response.send(name, *args)
535+
this_servlet_response.send(name, *args)
536536
end
537537
end
538538

0 commit comments

Comments
 (0)