Skip to content
This repository
Browse code

Fix 'rack.errors' not being set for Rack apps

  • Loading branch information...
commit d72a3a8d818fb3956b4d7aea13f44177b0c1fc82 1 parent e2c2e27
Alex Grant grantovich authored
1  lib/webmock/rack_response.rb
@@ -44,6 +44,7 @@ def build_rack_env(request)
44 44
45 45 # Rack-specific variables
46 46 env['rack.input'] = StringIO.new(body)
  47 + env['rack.errors'] = $stderr
47 48 env['rack.version'] = Rack::VERSION
48 49 env['rack.url_scheme'] = uri.scheme
49 50 env['rack.run_once'] = true
5 spec/support/my_rack_app.rb
@@ -2,7 +2,7 @@
2 2
3 3 class MyRackApp
4 4 class NonArrayResponse
5   - # The rack response body need not implement #join,
  5 + # The rack response body need not implement #join,
6 6 # but it must implement #each. It need not be an Array.
7 7 # ActionDispatch::Response, for example, exercises that fact.
8 8 # See: http://rack.rubyforge.org/doc/SPEC.html
@@ -32,6 +32,9 @@ def self.call(env)
32 32 else
33 33 [401, {}, [""]]
34 34 end
  35 + when ['GET', '/error']
  36 + env['rack.errors'].puts('Error!')
  37 + [500, {}, ['']]
35 38 else
36 39 [404, {}, ['']]
37 40 end
18 spec/unit/rack_response_spec.rb
@@ -49,6 +49,24 @@
49 49 response.body.should include('Good to meet you, Jimmy!')
50 50 end
51 51
  52 + describe 'rack error output' do
  53 + before :each do
  54 + @original_stderr = $stderr
  55 + $stderr = StringIO.new
  56 + end
  57 +
  58 + after :each do
  59 + $stderr = @original_stderr
  60 + end
  61 +
  62 + it 'should behave correctly when an app uses rack.errors' do
  63 + request = WebMock::RequestSignature.new(:get, 'www.example.com/error')
  64 +
  65 + expect { @rack_response.evaluate(request) }.to_not raise_error
  66 + expect($stderr.length).to_not eq 0
  67 + end
  68 + end
  69 +
52 70 describe 'basic auth request' do
53 71 before :each do
54 72 @rack_response_with_basic_auth = WebMock::RackResponse.new(

0 comments on commit d72a3a8

Please sign in to comment.
Something went wrong with that request. Please try again.