Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/webmock/rack_response.rb
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/support/my_rack_app.rb
Expand Up @@ -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
Expand Down Expand Up @@ -32,6 +32,9 @@ def self.call(env)
else
[401, {}, [""]]
end
when ['GET', '/error']
env['rack.errors'].puts('Error!')
[500, {}, ['']]
else
[404, {}, ['']]
end
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/rack_response_spec.rb
Expand Up @@ -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(
Expand Down