sinatra-symphony 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +30 -0
- data/lib/sinatra/symphony/test.rb +18 -0
- data/test/helper.rb +2 -32
- data/test/test_app.rb +22 -5
- metadata +21 -4
data/README.md
CHANGED
@@ -38,6 +38,36 @@ Time per request: 186.581 [ms] (mean, across all concurrent requests)
|
|
38
38
|
Transfer rate: 0.72 [Kbytes/sec] received
|
39
39
|
```
|
40
40
|
|
41
|
+
## Testing
|
42
|
+
|
43
|
+
Uses good old `rack-test` and a wrapper.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'minitest/autorun'
|
47
|
+
require 'sinatra/symphony/test'
|
48
|
+
|
49
|
+
class MiniTest::Spec
|
50
|
+
include Rack::Test::Methods
|
51
|
+
|
52
|
+
def app
|
53
|
+
Sinatra::Symphony::Test.new(@myapp)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'myapp' do
|
58
|
+
it 'should work' do
|
59
|
+
@myapp = Class.new(Sinatra::Symphony) do
|
60
|
+
get '/' do
|
61
|
+
'hello world'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
get '/'
|
66
|
+
assert_equal 'hello world', last_response.body
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
41
71
|
# See Also
|
42
72
|
[https://github.com/kyledrake/sinatra-synchrony](https://github.com/kyledrake/sinatra-synchrony)
|
43
73
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'sinatra-symphony'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
class Symphony::Test
|
6
|
+
def initialize app
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call env
|
11
|
+
EM.run do
|
12
|
+
env['async.callback'] = proc {|response| @response = response; EM.stop}
|
13
|
+
catch(:async) {@app.call(env)}
|
14
|
+
end
|
15
|
+
@response
|
16
|
+
end
|
17
|
+
end # Symphony::Test
|
18
|
+
end # Sinatra
|
data/test/helper.rb
CHANGED
@@ -2,38 +2,8 @@ require 'bundler/setup'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'em-synchrony/em-http'
|
4
4
|
require 'sinatra-symphony'
|
5
|
-
require '
|
6
|
-
require 'uri'
|
5
|
+
require 'sinatra/symphony/test'
|
7
6
|
|
8
7
|
class MiniTest::Spec
|
9
|
-
|
10
|
-
res = nil
|
11
|
-
server = fork do
|
12
|
-
capture_io do
|
13
|
-
Thin::Server.start('127.0.0.1', port, app)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
wait_for_service_start(port)
|
18
|
-
schedule_in_thread { res = block.call URI.parse("http://127.0.0.1:#{port}") }
|
19
|
-
return res
|
20
|
-
ensure
|
21
|
-
Process.kill 'KILL', server rescue nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def schedule_in_thread &block
|
25
|
-
EM.run do
|
26
|
-
EM.synchrony do
|
27
|
-
block.call
|
28
|
-
EM.stop
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def wait_for_service_start port, timeout = 5
|
34
|
-
(timeout / 0.1).to_i.times.each do
|
35
|
-
sleep 0.1
|
36
|
-
break if TCPSocket.new('127.0.0.1', port) rescue nil
|
37
|
-
end
|
38
|
-
end
|
8
|
+
include Rack::Test::Methods
|
39
9
|
end
|
data/test/test_app.rb
CHANGED
@@ -1,16 +1,33 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe 'sinatra-symphony app' do
|
4
|
+
def app
|
5
|
+
Sinatra::Symphony::Test.new(@myapp)
|
6
|
+
end
|
7
|
+
|
4
8
|
it 'should run' do
|
5
|
-
myapp = Class.new(Sinatra::Symphony) do
|
9
|
+
@myapp = Class.new(Sinatra::Symphony) do
|
6
10
|
get '/hello' do
|
7
11
|
'world'
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
assert_equal
|
14
|
-
|
15
|
+
get '/hello'
|
16
|
+
assert_equal 200, last_response.status
|
17
|
+
assert_equal 'world', last_response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should work with rack-test' do
|
21
|
+
@myapp = Class.new(Sinatra::Symphony) do
|
22
|
+
get '/' do
|
23
|
+
http = EM::HttpRequest.new('http://www.google.com/foobar').get
|
24
|
+
status http.response_header.status
|
25
|
+
'404'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/'
|
30
|
+
assert_equal 404, last_response.status
|
31
|
+
assert_equal '404', last_response.body
|
15
32
|
end
|
16
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-symphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-test
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: em-http-request
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +123,7 @@ dependencies:
|
|
107
123
|
- - ! '>='
|
108
124
|
- !ruby/object:Gem::Version
|
109
125
|
version: '0'
|
110
|
-
description: em-synchrony glue for sinatra
|
126
|
+
description: em-synchrony glue for sinatra.
|
111
127
|
email:
|
112
128
|
- deepfryed@gmail.com
|
113
129
|
executables: []
|
@@ -117,6 +133,7 @@ files:
|
|
117
133
|
- test/helper.rb
|
118
134
|
- test/test_app.rb
|
119
135
|
- lib/sinatra/symphony.rb
|
136
|
+
- lib/sinatra/symphony/test.rb
|
120
137
|
- lib/sinatra-symphony.rb
|
121
138
|
- README.md
|
122
139
|
homepage: http://github.com/deepfryed/sinatra-symphony
|
@@ -139,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
156
|
version: '0'
|
140
157
|
requirements: []
|
141
158
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.8.
|
159
|
+
rubygems_version: 1.8.24
|
143
160
|
signing_key:
|
144
161
|
specification_version: 3
|
145
162
|
summary: em-synchrony glue for sinatra
|