rack-async2sync 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +26 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/rack/async2sync.rb +57 -0
- data/rack-async2sync.gemspec +57 -0
- data/test/helper.rb +27 -0
- data/test/test_rack_async2sync.rb +20 -0
- metadata +95 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Cyril Rohr
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= rack-async2sync
|
2
|
+
A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests
|
3
|
+
Useful for testing with a minimum of changes in your testing environment.
|
4
|
+
|
5
|
+
class MyAsyncRackApp < Sinatra::Base
|
6
|
+
register Sinatra::Async
|
7
|
+
aget '/delay/:n' do |n|
|
8
|
+
content_type :txt
|
9
|
+
EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestRackAsync2Sync < Test::Unit::TestCase
|
14
|
+
test "gets the response for an async request" do
|
15
|
+
@app = Rack::Async2Sync.new(MyAsyncRackApp)
|
16
|
+
get '/delay/1'
|
17
|
+
assert last_response.ok?
|
18
|
+
assert_equal "delayed for 1 seconds", last_response.body
|
19
|
+
assert_equal "text/plain", last_response.headers['Content-Type']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
== Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2009 Cyril Rohr. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-async2sync"
|
8
|
+
gem.summary = %Q{A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests.}
|
9
|
+
gem.description = %Q{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.}
|
10
|
+
gem.email = "cyril.rohr@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/crohr/rack-async2sync"
|
12
|
+
gem.authors = ["Cyril Rohr"]
|
13
|
+
gem.add_development_dependency "contest"
|
14
|
+
gem.add_dependency "eventmachine"
|
15
|
+
gem.add_dependency "async_sinatra"
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "rack-async2sync #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
module Rack
|
3
|
+
# A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests
|
4
|
+
# Useful for testing with a minimum of changes in your testing environment.
|
5
|
+
# e.g.
|
6
|
+
# require 'sinatra/base'
|
7
|
+
# require 'sinatra/async'
|
8
|
+
# require 'rack/async2sync'
|
9
|
+
# require 'spec'
|
10
|
+
# require 'rack/test'
|
11
|
+
# Test::Unit::TestCase.send :include, Rack::Test::Methods
|
12
|
+
#
|
13
|
+
# class MyAsyncRackApp < Sinatra::Base
|
14
|
+
# register Sinatra::Async
|
15
|
+
# aget '/delay/:n' do |n|
|
16
|
+
# EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def app
|
21
|
+
# Rack::Async2Sync.new(MyAsyncRackApp)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "requests the /delay/:n asynchronous method" do
|
25
|
+
# get '/delay/2'
|
26
|
+
# # you can use the usual methods of Rack::Test::Methods
|
27
|
+
# last_response.status.should == 200
|
28
|
+
# last_response.body.should == "delayed for 2 seconds"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# Author: Cyril Rohr (cyril.rohr@irisa.fr)
|
32
|
+
#
|
33
|
+
class Async2Sync
|
34
|
+
class AsyncResponse
|
35
|
+
attr_reader :status, :headers, :body
|
36
|
+
# used to register the response given by async_sinatra in the 'async.callback' env variable.
|
37
|
+
def [](response)
|
38
|
+
@status, @headers, @body = response
|
39
|
+
EM.stop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(app, options = {})
|
44
|
+
@app = app
|
45
|
+
end
|
46
|
+
|
47
|
+
def call(env)
|
48
|
+
response = AsyncResponse.new
|
49
|
+
EM.run do
|
50
|
+
catch(:async) do
|
51
|
+
@app.call(env.merge('async.callback' => response))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
[response.status, response.headers, response.body]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack-async2sync}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Cyril Rohr"]
|
12
|
+
s.date = %q{2009-11-17}
|
13
|
+
s.description = %q{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.}
|
14
|
+
s.email = %q{cyril.rohr@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"test/helper.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/crohr/rack-async2sync}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.5}
|
32
|
+
s.summary = %q{A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests.}
|
33
|
+
s.test_files = [
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_rack_async2sync.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<contest>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
45
|
+
s.add_runtime_dependency(%q<async_sinatra>, [">= 0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<contest>, [">= 0"])
|
48
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
49
|
+
s.add_dependency(%q<async_sinatra>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<contest>, [">= 0"])
|
53
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
54
|
+
s.add_dependency(%q<async_sinatra>, [">= 0"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'rack'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rack'
|
6
|
+
end
|
7
|
+
|
8
|
+
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
9
|
+
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
10
|
+
|
11
|
+
require 'contest'
|
12
|
+
require 'rack/test'
|
13
|
+
require 'sinatra/base'
|
14
|
+
require 'sinatra/async'
|
15
|
+
require 'rack/async2sync'
|
16
|
+
|
17
|
+
class Sinatra::Base
|
18
|
+
# Allow assertions in request context
|
19
|
+
include Test::Unit::Assertions
|
20
|
+
end
|
21
|
+
|
22
|
+
class Test::Unit::TestCase
|
23
|
+
include Rack::Test::Methods
|
24
|
+
def app
|
25
|
+
Rack::Lint.new(@app)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class MyAsyncRackApp < Sinatra::Base
|
4
|
+
register Sinatra::Async
|
5
|
+
aget '/delay/:n' do |n|
|
6
|
+
content_type :txt
|
7
|
+
EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class TestRackAsync2Sync < Test::Unit::TestCase
|
13
|
+
test "gets the response for an async request" do
|
14
|
+
@app = Rack::Async2Sync.new(MyAsyncRackApp)
|
15
|
+
get '/delay/1'
|
16
|
+
assert last_response.ok?
|
17
|
+
assert_equal "delayed for 1 seconds", last_response.body
|
18
|
+
assert_equal "text/plain", last_response.headers['Content-Type']
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-async2sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyril Rohr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-17 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: contest
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: eventmachine
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: async_sinatra
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: 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.
|
46
|
+
email: cyril.rohr@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/rack/async2sync.rb
|
62
|
+
- rack-async2sync.gemspec
|
63
|
+
- test/helper.rb
|
64
|
+
- test/test_rack_async2sync.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/crohr/rack-async2sync
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: A Rack middleware that transforms async requests (using thin + async_sinatra for example) into synchronous requests.
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_rack_async2sync.rb
|