Skip to content

Commit c8083a2

Browse files
committed
Fix jruby + rspec-mocks + HttpStreamingResponse + read_timeout= problem
1 parent 092e3cc commit c8083a2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

spec/rack/reverse_proxy_spec.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ def dummy_app
1111
lambda { |env| [200, {}, ['Dummy App']] }
1212
end
1313

14+
let(:http_streaming_response) {
15+
double(
16+
"Rack::HttpStreamingResponse",
17+
:use_ssl= => nil,
18+
:verify_mode= => nil,
19+
:headers => {},
20+
:status => 200,
21+
:body => "OK"
22+
)
23+
}
24+
1425
describe "as middleware" do
1526
def app
1627
Rack::ReverseProxy.new(dummy_app) do
@@ -145,7 +156,8 @@ def app
145156

146157
it "should make request with basic auth" do
147158
stub_request(:get, "http://example.com/test/slow")
148-
Rack::HttpStreamingResponse.any_instance.should_receive(:read_timeout=).with(99)
159+
allow(Rack::HttpStreamingResponse).to receive(:new).and_return(http_streaming_response)
160+
expect(http_streaming_response).to receive(:read_timeout=).with(99)
149161
get '/test/slow'
150162
end
151163
end
@@ -159,7 +171,8 @@ def app
159171

160172
it "should make request with basic auth" do
161173
stub_request(:get, "http://example.com/test/slow")
162-
Rack::HttpStreamingResponse.any_instance.should_not_receive(:read_timeout=)
174+
allow(Rack::HttpStreamingResponse).to receive(:new).and_return(http_streaming_response)
175+
expect(http_streaming_response).not_to receive(:read_timeout=)
163176
get '/test/slow'
164177
end
165178
end

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
config.expect_with :rspec do |expectations|
1414
# This option will default to `true` in RSpec 4.
1515
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
16-
expectations.syntax = [:should]
16+
expectations.syntax = [:should, :expect]
1717
end
1818
config.mock_with :rspec do |mocks|
1919
mocks.verify_doubled_constant_names = true
2020
mocks.verify_partial_doubles = true
21-
mocks.syntax = [:should]
21+
mocks.syntax = [:should, :expect]
2222
# Prevents you from mocking or stubbing a method that does not exist on
2323
# a real object. This is generally recommended, and will default to
2424
# `true` in RSpec 4.

0 commit comments

Comments
 (0)