nyny 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +20 -20
- data/.rspec +2 -2
- data/.ruby-version +1 -1
- data/.travis.yml +11 -11
- data/CHANGELOG +45 -40
- data/Gemfile +7 -8
- data/LICENSE.txt +22 -22
- data/Performance.md +41 -46
- data/README.md +423 -423
- data/Rakefile +6 -6
- data/benchmark.rb +116 -125
- data/lib/nyny.rb +33 -33
- data/lib/nyny/app.rb +79 -79
- data/lib/nyny/core-ext/runner.rb +19 -19
- data/lib/nyny/core-ext/templates.rb +20 -20
- data/lib/nyny/primitives.rb +25 -25
- data/lib/nyny/request_scope.rb +43 -43
- data/lib/nyny/route.rb +40 -40
- data/lib/nyny/router.rb +46 -44
- data/lib/nyny/version.rb +3 -3
- data/nyny.gemspec +29 -27
- data/spec/app_spec.rb +248 -248
- data/spec/inheritance_spec.rb +76 -75
- data/spec/nyny_spec.rb +11 -11
- data/spec/primitives_spec.rb +33 -33
- data/spec/request_scope_spec.rb +103 -103
- data/spec/router_spec.rb +29 -21
- data/spec/runner_spec.rb +23 -23
- data/spec/spec_helper.rb +61 -61
- data/spec/templates_spec.rb +52 -52
- data/spec/views/layout.erb +6 -6
- metadata +3 -3
data/spec/inheritance_spec.rb
CHANGED
@@ -1,76 +1,77 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NYNY::App do
|
4
|
-
describe 'inheritance' do
|
5
|
-
class Parent < NYNY::App
|
6
|
-
helpers do
|
7
|
-
def parent_helper; :parent; end
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
headers['parent before'] = 'true'
|
12
|
-
end
|
13
|
-
|
14
|
-
after do
|
15
|
-
headers['parent after'] = 'true'
|
16
|
-
end
|
17
|
-
|
18
|
-
get '/helpers' do
|
19
|
-
parent_helper.should == :parent
|
20
|
-
end
|
21
|
-
|
22
|
-
get '/parent' do
|
23
|
-
'parent'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Child < Parent
|
28
|
-
helpers do
|
29
|
-
def child_helper; :child; end
|
30
|
-
end
|
31
|
-
|
32
|
-
before do
|
33
|
-
headers['child before'] = 'true'
|
34
|
-
end
|
35
|
-
|
36
|
-
after do
|
37
|
-
headers['child after'] = 'true'
|
38
|
-
end
|
39
|
-
|
40
|
-
get '/helpers' do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
let (:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
parent.get('/
|
55
|
-
|
56
|
-
child.get('/
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
child.get('/parent').headers['
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
child.get('/parent').headers['
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NYNY::App do
|
4
|
+
describe 'inheritance' do
|
5
|
+
class Parent < NYNY::App
|
6
|
+
helpers do
|
7
|
+
def parent_helper; :parent; end
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
headers['parent before'] = 'true'
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
headers['parent after'] = 'true'
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/helpers' do
|
19
|
+
parent_helper.should == :parent
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/parent' do
|
23
|
+
'parent'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Child < Parent
|
28
|
+
helpers do
|
29
|
+
def child_helper; :child; end
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
headers['child before'] = 'true'
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
headers['child after'] = 'true'
|
38
|
+
end
|
39
|
+
|
40
|
+
get '/helpers' do
|
41
|
+
parent_helper.should == :parent
|
42
|
+
child_helper.should == :child
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/child' do
|
46
|
+
'child'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
let (:parent) { Rack::MockRequest.new Parent.new }
|
51
|
+
let (:child) { Rack::MockRequest.new Child.new }
|
52
|
+
|
53
|
+
it 'works correctly for routes' do
|
54
|
+
parent.get('/parent').body.should == 'parent'
|
55
|
+
parent.get('/child').status.should == 404
|
56
|
+
child.get('/parent').body.should == 'parent'
|
57
|
+
child.get('/child').body.should == 'child'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'works correctly for before filters' do
|
61
|
+
parent.get('/parent').headers['child before'].should be_nil
|
62
|
+
child.get('/parent').headers['child before'].should_not be_nil
|
63
|
+
child.get('/parent').headers['parent before'].should_not be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'works correctly for after filters' do
|
67
|
+
parent.get('/parent').headers['child after'].should be_nil
|
68
|
+
child.get('/parent').headers['child after'].should_not be_nil
|
69
|
+
child.get('/parent').headers['parent after'].should_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'works correctly for helpers' do
|
73
|
+
parent.get('/helpers')
|
74
|
+
child.get('/helpers')
|
75
|
+
end
|
76
|
+
end
|
76
77
|
end
|
data/spec/nyny_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NYNY do
|
4
|
-
it '.root points to pwd' do
|
5
|
-
NYNY.root.should == Dir.pwd
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'has the correct env' do
|
9
|
-
NYNY.env.should be_test
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NYNY do
|
4
|
+
it '.root points to pwd' do
|
5
|
+
NYNY.root.should == Dir.pwd
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'has the correct env' do
|
9
|
+
NYNY.env.should be_test
|
10
|
+
end
|
11
|
+
end
|
data/spec/primitives_spec.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Request do
|
4
|
-
let (:subject) { Request.new double }
|
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 = double
|
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 = double
|
22
|
-
res.body = raw_body
|
23
|
-
res.raw_body.should == raw_body
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should set the iterable as the raw body as well' do
|
27
|
-
res = Response.new
|
28
|
-
raw_body = ['one', 'two']
|
29
|
-
res.body = raw_body
|
30
|
-
res.raw_body.should == raw_body
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Request do
|
4
|
+
let (:subject) { Request.new double }
|
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 = double
|
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 = double
|
22
|
+
res.body = raw_body
|
23
|
+
res.raw_body.should == raw_body
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set the iterable as the raw body as well' do
|
27
|
+
res = Response.new
|
28
|
+
raw_body = ['one', 'two']
|
29
|
+
res.body = raw_body
|
30
|
+
res.raw_body.should == raw_body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/request_scope_spec.rb
CHANGED
@@ -1,103 +1,103 @@
|
|
1
|
-
require '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 dummy_request }
|
7
|
-
let (:handler) {
|
8
|
-
Proc.new {"hello"}
|
9
|
-
}
|
10
|
-
|
11
|
-
describe 'exposed methods' do
|
12
|
-
its (:params) { should == dummy_request.params }
|
13
|
-
its (:cookies) { should == dummy_request.cookies }
|
14
|
-
its (:session) { should == dummy_request.session }
|
15
|
-
|
16
|
-
it 'params should have insensitive keys' do
|
17
|
-
app = mock_app do
|
18
|
-
get '/' do
|
19
|
-
params[:foo].should == params['foo']
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
app.get '/?foo=bar'
|
24
|
-
end
|
25
|
-
|
26
|
-
it '#headers should set the header values' do
|
27
|
-
subject.headers['Head'] = 'Tail'
|
28
|
-
response = subject.apply_to &handler
|
29
|
-
response[1]['Head'].should == 'Tail'
|
30
|
-
end
|
31
|
-
|
32
|
-
it '#status should set the response status' do
|
33
|
-
forbid = Proc.new { status 403 }
|
34
|
-
response = subject.apply_to &forbid
|
35
|
-
response[0].should == 403
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'params should have insensitive keys' do
|
39
|
-
app = mock_app do
|
40
|
-
get '/' do
|
41
|
-
params[:foo].should == params['foo']
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
app.get '/?foo=bar'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'halt in a before block should override the response' do
|
49
|
-
prc = Proc.new { 'da block' }
|
50
|
-
|
51
|
-
app = mock_app do
|
52
|
-
before do
|
53
|
-
halt 302
|
54
|
-
end
|
55
|
-
|
56
|
-
get '/', &prc
|
57
|
-
end
|
58
|
-
|
59
|
-
res = app.get '/'
|
60
|
-
res.status.should == 302
|
61
|
-
prc.should_not_receive(:call)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should halt if the statement is in the route definition' do
|
65
|
-
app = mock_app do
|
66
|
-
get '/' do
|
67
|
-
halt 200, {}, 'Halted'
|
68
|
-
'shouldnt be returned'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
res = app.get '/'
|
72
|
-
res.status.should == 200
|
73
|
-
res.body.should == 'Halted'
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'return prematurely with pass' do
|
77
|
-
app = mock_app do
|
78
|
-
get '/' do
|
79
|
-
next 'hui'
|
80
|
-
'shouldnt be returned'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
res = app.get '/'
|
84
|
-
res.status.should == 200
|
85
|
-
res.body.should == 'hui'
|
86
|
-
end
|
87
|
-
|
88
|
-
it '#redirect_to should redirect' do
|
89
|
-
redir = Proc.new { redirect_to 'http://foo.bar' }
|
90
|
-
response = catch(:halt) { subject.apply_to &redir }
|
91
|
-
response[0] == 302
|
92
|
-
response[1]['Location'].should == 'http://foo.bar'
|
93
|
-
end
|
94
|
-
|
95
|
-
it '#apply_to should return a Rack response' do
|
96
|
-
response = subject.apply_to &handler
|
97
|
-
response.length.should == 3
|
98
|
-
response[0].should == 200
|
99
|
-
response[1].should == subject.headers
|
100
|
-
response[2].should be_a(Rack::BodyProxy)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
1
|
+
require '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 dummy_request }
|
7
|
+
let (:handler) {
|
8
|
+
Proc.new {"hello"}
|
9
|
+
}
|
10
|
+
|
11
|
+
describe 'exposed methods' do
|
12
|
+
its (:params) { should == dummy_request.params }
|
13
|
+
its (:cookies) { should == dummy_request.cookies }
|
14
|
+
its (:session) { should == dummy_request.session }
|
15
|
+
|
16
|
+
it 'params should have insensitive keys' do
|
17
|
+
app = mock_app do
|
18
|
+
get '/' do
|
19
|
+
params[:foo].should == params['foo']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
app.get '/?foo=bar'
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#headers should set the header values' do
|
27
|
+
subject.headers['Head'] = 'Tail'
|
28
|
+
response = subject.apply_to &handler
|
29
|
+
response[1]['Head'].should == 'Tail'
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#status should set the response status' do
|
33
|
+
forbid = Proc.new { status 403 }
|
34
|
+
response = subject.apply_to &forbid
|
35
|
+
response[0].should == 403
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'params should have insensitive keys' do
|
39
|
+
app = mock_app do
|
40
|
+
get '/' do
|
41
|
+
params[:foo].should == params['foo']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
app.get '/?foo=bar'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'halt in a before block should override the response' do
|
49
|
+
prc = Proc.new { 'da block' }
|
50
|
+
|
51
|
+
app = mock_app do
|
52
|
+
before do
|
53
|
+
halt 302
|
54
|
+
end
|
55
|
+
|
56
|
+
get '/', &prc
|
57
|
+
end
|
58
|
+
|
59
|
+
res = app.get '/'
|
60
|
+
res.status.should == 302
|
61
|
+
prc.should_not_receive(:call)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should halt if the statement is in the route definition' do
|
65
|
+
app = mock_app do
|
66
|
+
get '/' do
|
67
|
+
halt 200, {}, 'Halted'
|
68
|
+
'shouldnt be returned'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
res = app.get '/'
|
72
|
+
res.status.should == 200
|
73
|
+
res.body.should == 'Halted'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'return prematurely with pass' do
|
77
|
+
app = mock_app do
|
78
|
+
get '/' do
|
79
|
+
next 'hui'
|
80
|
+
'shouldnt be returned'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
res = app.get '/'
|
84
|
+
res.status.should == 200
|
85
|
+
res.body.should == 'hui'
|
86
|
+
end
|
87
|
+
|
88
|
+
it '#redirect_to should redirect' do
|
89
|
+
redir = Proc.new { redirect_to 'http://foo.bar' }
|
90
|
+
response = catch(:halt) { subject.apply_to &redir }
|
91
|
+
response[0] == 302
|
92
|
+
response[1]['Location'].should == 'http://foo.bar'
|
93
|
+
end
|
94
|
+
|
95
|
+
it '#apply_to should return a Rack response' do
|
96
|
+
response = subject.apply_to &handler
|
97
|
+
response.length.should == 3
|
98
|
+
response[0].should == 200
|
99
|
+
response[1].should == subject.headers
|
100
|
+
response[2].should be_a(Rack::BodyProxy)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|