A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests. Useful for testing Async Sinatra apps with a minimum of changes in your testing environment.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/rack
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
rack-async2sync.gemspec

README.rdoc

rack-async2sync

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

Copyright © 2009 Cyril Rohr. See LICENSE for details.