A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests Useful for testing with a minimum of changes in your testing environment.
class MyAsyncRackApp < Sinatra::Base register Sinatra::Async aget '/delay/:n' do |n| content_type :txt EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } } end end class TestRackAsync2Sync < Test::Unit::TestCase test "gets the response for an async request" do @app = Rack::Async2Sync.new(MyAsyncRackApp) get '/delay/1' assert last_response.ok? assert_equal "delayed for 1 seconds", last_response.body assert_equal "text/plain", last_response.headers['Content-Type'] end end
Copyright © 2009 Cyril Rohr. See LICENSE for details.