Permalink
Browse files

Merge pull request #223 from grantovich/acg-fix-rack-errors

Fix 'rack.errors' not being set for Rack apps
  • Loading branch information...
2 parents a140843 + d72a3a8 commit 0d7abd3ae2e1c1af52cb8d810fb8ece286509863 @bblimke committed Feb 17, 2013
Showing with 23 additions and 1 deletion.
  1. +1 −0 lib/webmock/rack_response.rb
  2. +4 −1 spec/support/my_rack_app.rb
  3. +18 −0 spec/unit/rack_response_spec.rb
View
1 lib/webmock/rack_response.rb
@@ -44,6 +44,7 @@ def build_rack_env(request)
# Rack-specific variables
env['rack.input'] = StringIO.new(body)
+ env['rack.errors'] = $stderr
env['rack.version'] = Rack::VERSION
env['rack.url_scheme'] = uri.scheme
env['rack.run_once'] = true
View
5 spec/support/my_rack_app.rb
@@ -2,7 +2,7 @@
class MyRackApp
class NonArrayResponse
- # The rack response body need not implement #join,
+ # The rack response body need not implement #join,
# but it must implement #each. It need not be an Array.
# ActionDispatch::Response, for example, exercises that fact.
# See: http://rack.rubyforge.org/doc/SPEC.html
@@ -32,6 +32,9 @@ def self.call(env)
else
[401, {}, [""]]
end
+ when ['GET', '/error']
+ env['rack.errors'].puts('Error!')
+ [500, {}, ['']]
else
[404, {}, ['']]
end
View
18 spec/unit/rack_response_spec.rb
@@ -49,6 +49,24 @@
response.body.should include('Good to meet you, Jimmy!')
end
+ describe 'rack error output' do
+ before :each do
+ @original_stderr = $stderr
+ $stderr = StringIO.new
+ end
+
+ after :each do
+ $stderr = @original_stderr
+ end
+
+ it 'should behave correctly when an app uses rack.errors' do
+ request = WebMock::RequestSignature.new(:get, 'www.example.com/error')
+
+ expect { @rack_response.evaluate(request) }.to_not raise_error
+ expect($stderr.length).to_not eq 0
+ end
+ end
+
describe 'basic auth request' do
before :each do
@rack_response_with_basic_auth = WebMock::RackResponse.new(

0 comments on commit 0d7abd3

Please sign in to comment.