Created
December 29, 2012 22:16
-
-
Save challengee/4409677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'commute/core/context' | |
require 'commute/core/stack' | |
describe Commute::Stack do | |
let(:stack) { Commute::Stack.new } | |
# A Layer that forwards to the next. | |
let(:forward_layer) { proc { |router, request, options = {}| | |
request.pipe router.call(request.http) { |response, status| | |
response.pipe request.respond(response.http, status) | |
} | |
}} | |
# A layer that echoes all data. | |
let(:echo_layer) { proc { |router, request, options = {}| | |
request.pipe request.respond(Commute::Http::Response.new(request), Commute::Status.ok) | |
}} | |
describe '#call' do | |
describe 'with a forward and echo layer' do | |
it 'should echo all data' do | |
# Append a forward and echo layer to the main sequence. | |
stack.sequence do |s| | |
s.append forward_layer | |
s.append echo_layer | |
end | |
# Call the stack. | |
context = Commute::Context.new stack | |
request = stack.call Commute::Http::Request.new(context) do |response, status| | |
puts 'response!' | |
response.on(:data) { |chunk| puts chunk } | |
end | |
request.write 1 | |
request.write 2 | |
request.end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment