nyny 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/Performance.md +65 -0
- data/README.md +167 -0
- data/Rakefile +1 -0
- data/benchmarks/filters/frankie.rb +18 -0
- data/benchmarks/filters/sinatra.rb +17 -0
- data/benchmarks/helpers/frankie.rb +19 -0
- data/benchmarks/helpers/sinatra.rb +18 -0
- data/benchmarks/simple/frankie.rb +10 -0
- data/benchmarks/simple/sinatra.rb +9 -0
- data/benchmarks/url_pattern/frankie.rb +10 -0
- data/benchmarks/url_pattern/sinatra.rb +8 -0
- data/examples/active_record/.gitignore +1 -0
- data/examples/active_record/Gemfile +14 -0
- data/examples/active_record/Rakefile +51 -0
- data/examples/active_record/config/database.yml +0 -0
- data/examples/active_record/database.rb +12 -0
- data/examples/active_record/db/migrate/20130606133756_add_shouts.rb +12 -0
- data/examples/active_record/models/shout.rb +3 -0
- data/examples/active_record/server.rb +43 -0
- data/examples/json_api.rb +21 -0
- data/examples/templates/server.rb +27 -0
- data/examples/templates/views/index.haml +1 -0
- data/examples/web_sockets/public/FABridge.js +604 -0
- data/examples/web_sockets/public/WebSocketMain.swf +0 -0
- data/examples/web_sockets/public/index.html +76 -0
- data/examples/web_sockets/public/swfobject.js +4 -0
- data/examples/web_sockets/public/web_socket.js +388 -0
- data/examples/web_sockets/server.rb +60 -0
- data/lib/nyny.rb +9 -0
- data/lib/nyny/app.rb +66 -0
- data/lib/nyny/class_level_api.rb +40 -0
- data/lib/nyny/primitives.rb +25 -0
- data/lib/nyny/request_scope.rb +60 -0
- data/lib/nyny/route_signature.rb +44 -0
- data/lib/nyny/version.rb +3 -0
- data/nyny.gemspec +24 -0
- data/spec/app_spec.rb +144 -0
- data/spec/class_level_api_spec.rb +39 -0
- data/spec/primitives_spec.rb +26 -0
- data/spec/request_scope_spec.rb +71 -0
- data/spec/spec_helper.rb +42 -0
- metadata +138 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe ClassLevelApi do
|
4
|
+
let (:app_class) { Class.new(App) }
|
5
|
+
describe 'middlewares' do
|
6
|
+
let (:app_class) do
|
7
|
+
frankie_app do
|
8
|
+
use NullMiddleware
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow to add a middleware' do
|
13
|
+
app_class.middlewares.last.first.should == NullMiddleware
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should call the middleware when called' do
|
17
|
+
app = app_class.new
|
18
|
+
top = app.instance_variable_get '@top'
|
19
|
+
top.class.should == NullMiddleware
|
20
|
+
top.should_receive :call
|
21
|
+
app.call Rack::MockRequest.env_for '/'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'helpers' do
|
26
|
+
it 'should allow to include a helper in request scope' do
|
27
|
+
app_class.helpers NullHelper
|
28
|
+
RequestScope.ancestors.should include(NullHelper)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should allow to include multiple helpers modules' do
|
32
|
+
module NullHelper2
|
33
|
+
end
|
34
|
+
|
35
|
+
app_class.helpers NullHelper, NullHelper2
|
36
|
+
RequestScope.ancestors.should include(NullHelper, NullHelper2)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Request do
|
4
|
+
let (:subject) { Request.new stub }
|
5
|
+
|
6
|
+
it { should be_a(Rack::Request) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Response do
|
10
|
+
it { should be_a(Rack::Response) }
|
11
|
+
|
12
|
+
describe '#raw_body' do
|
13
|
+
it 'should be accesible when the response was initialized' do
|
14
|
+
raw_body = stub
|
15
|
+
res = Response.new raw_body
|
16
|
+
res.raw_body.should == raw_body
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should accesible after body was set' do
|
20
|
+
res = Response.new
|
21
|
+
raw_body = stub
|
22
|
+
res.body = raw_body
|
23
|
+
res.raw_body.should == raw_body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe RequestScope do
|
4
|
+
let (:env) { Rack::MockRequest.env_for '/', :params => {:some => 'param'} }
|
5
|
+
let (:dummy_request) { Rack::Request.new(env) }
|
6
|
+
let (:subject) { RequestScope.new App.new, dummy_request }
|
7
|
+
let (:handler) {
|
8
|
+
Proc.new {"hello"}
|
9
|
+
}
|
10
|
+
|
11
|
+
it 'should be able to add a helper module' do
|
12
|
+
RequestScope.add_helper_module NullHelper
|
13
|
+
RequestScope.ancestors.should include(NullHelper)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'exposed methods' do
|
17
|
+
its (:params) { should == dummy_request.params }
|
18
|
+
its (:cookies) { should == dummy_request.cookies }
|
19
|
+
its (:session) { should == dummy_request.session }
|
20
|
+
|
21
|
+
it '#headers should set the header values' do
|
22
|
+
subject.headers 'Head' => 'Tail'
|
23
|
+
response = subject.apply_to &handler
|
24
|
+
response.headers['Head'].should == 'Tail'
|
25
|
+
end
|
26
|
+
|
27
|
+
it '#status should set the response status' do
|
28
|
+
forbid = Proc.new { status 403 }
|
29
|
+
response = subject.apply_to &forbid
|
30
|
+
response.status.should == 403
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'params should have insensitive keys' do
|
34
|
+
app = mock_app do
|
35
|
+
get '/' do
|
36
|
+
params[:foo].should == params['foo']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
app.get '/?foo=bar'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'halt in a before block should override the response' do
|
44
|
+
prc = Proc.new { 'da block' }
|
45
|
+
|
46
|
+
app = mock_app do
|
47
|
+
before do
|
48
|
+
halt 302
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/', &prc
|
52
|
+
end
|
53
|
+
|
54
|
+
res = app.get '/'
|
55
|
+
res.status.should == 302
|
56
|
+
prc.should_not_receive(:call)
|
57
|
+
end
|
58
|
+
|
59
|
+
it '#redirect_to should redirect' do
|
60
|
+
redir = Proc.new { redirect_to 'http://foo.bar' }
|
61
|
+
response = subject.apply_to &redir
|
62
|
+
response.status.should == 302
|
63
|
+
response.headers['Location'].should == 'http://foo.bar'
|
64
|
+
end
|
65
|
+
|
66
|
+
it '#apply_to should return a Rack response' do
|
67
|
+
response = subject.apply_to &handler
|
68
|
+
response.should be_a(Rack::Response)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'nyny'
|
2
|
+
require 'rack'
|
3
|
+
require 'securerandom'
|
4
|
+
include NYNY
|
5
|
+
|
6
|
+
class Rack::MockRequest
|
7
|
+
def trace(uri, opts={}) request("TRACE", uri, opts) end
|
8
|
+
def options(uri, opts={}) request("OPTIONS", uri, opts) end
|
9
|
+
end
|
10
|
+
|
11
|
+
def extended_modules_for kls
|
12
|
+
(class << kls; self end).included_modules
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_app &blk
|
16
|
+
Rack::MockRequest.new frankie_app(&blk).new
|
17
|
+
end
|
18
|
+
|
19
|
+
def frankie_app &blk
|
20
|
+
Class.new(App, &blk)
|
21
|
+
end
|
22
|
+
|
23
|
+
def random_url levels=1
|
24
|
+
parts = levels.times.map do
|
25
|
+
SecureRandom.urlsafe_base64
|
26
|
+
end
|
27
|
+
|
28
|
+
"/#{parts.join('/')}"
|
29
|
+
end
|
30
|
+
|
31
|
+
class NullMiddleware
|
32
|
+
def initialize app
|
33
|
+
@app = app
|
34
|
+
end
|
35
|
+
|
36
|
+
def call env
|
37
|
+
@app.call env
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module NullHelper
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nyny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Lisnic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: New York, New York.
|
56
|
+
email:
|
57
|
+
- andrei.lisnic@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .ruby-gemset
|
65
|
+
- .ruby-version
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- Performance.md
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- benchmarks/filters/frankie.rb
|
72
|
+
- benchmarks/filters/sinatra.rb
|
73
|
+
- benchmarks/helpers/frankie.rb
|
74
|
+
- benchmarks/helpers/sinatra.rb
|
75
|
+
- benchmarks/simple/frankie.rb
|
76
|
+
- benchmarks/simple/sinatra.rb
|
77
|
+
- benchmarks/url_pattern/frankie.rb
|
78
|
+
- benchmarks/url_pattern/sinatra.rb
|
79
|
+
- examples/active_record/.gitignore
|
80
|
+
- examples/active_record/Gemfile
|
81
|
+
- examples/active_record/Rakefile
|
82
|
+
- examples/active_record/config/database.yml
|
83
|
+
- examples/active_record/database.rb
|
84
|
+
- examples/active_record/db/migrate/20130606133756_add_shouts.rb
|
85
|
+
- examples/active_record/models/shout.rb
|
86
|
+
- examples/active_record/server.rb
|
87
|
+
- examples/json_api.rb
|
88
|
+
- examples/templates/server.rb
|
89
|
+
- examples/templates/views/index.haml
|
90
|
+
- examples/web_sockets/public/FABridge.js
|
91
|
+
- examples/web_sockets/public/WebSocketMain.swf
|
92
|
+
- examples/web_sockets/public/index.html
|
93
|
+
- examples/web_sockets/public/swfobject.js
|
94
|
+
- examples/web_sockets/public/web_socket.js
|
95
|
+
- examples/web_sockets/server.rb
|
96
|
+
- lib/nyny.rb
|
97
|
+
- lib/nyny/app.rb
|
98
|
+
- lib/nyny/class_level_api.rb
|
99
|
+
- lib/nyny/primitives.rb
|
100
|
+
- lib/nyny/request_scope.rb
|
101
|
+
- lib/nyny/route_signature.rb
|
102
|
+
- lib/nyny/version.rb
|
103
|
+
- nyny.gemspec
|
104
|
+
- spec/app_spec.rb
|
105
|
+
- spec/class_level_api_spec.rb
|
106
|
+
- spec/primitives_spec.rb
|
107
|
+
- spec/request_scope_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: https://github.com/alisnic/nyny
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>'
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.3.1
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.0.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: sinatra's little brother
|
133
|
+
test_files:
|
134
|
+
- spec/app_spec.rb
|
135
|
+
- spec/class_level_api_spec.rb
|
136
|
+
- spec/primitives_spec.rb
|
137
|
+
- spec/request_scope_spec.rb
|
138
|
+
- spec/spec_helper.rb
|