nyny 2.2.1 → 3.0.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.
- checksums.yaml +4 -4
- data/.gitignore +20 -20
- data/.rspec +2 -2
- data/.ruby-version +1 -1
- data/.travis.yml +11 -12
- data/CHANGELOG +40 -27
- data/Gemfile +8 -8
- data/LICENSE.txt +22 -22
- data/Performance.md +46 -44
- data/README.md +423 -381
- data/Rakefile +6 -6
- data/benchmark.rb +125 -125
- data/lib/nyny.rb +33 -36
- data/lib/nyny/app.rb +79 -67
- data/lib/nyny/core-ext/runner.rb +19 -19
- data/lib/nyny/core-ext/templates.rb +20 -18
- data/lib/nyny/primitives.rb +25 -25
- data/lib/nyny/request_scope.rb +43 -52
- data/lib/nyny/route.rb +40 -40
- data/lib/nyny/router.rb +44 -43
- data/lib/nyny/version.rb +3 -3
- data/nyny.gemspec +27 -26
- data/spec/app_spec.rb +248 -200
- data/spec/inheritance_spec.rb +76 -0
- data/spec/nyny_spec.rb +11 -11
- data/spec/primitives_spec.rb +33 -33
- data/spec/request_scope_spec.rb +103 -105
- data/spec/router_spec.rb +21 -21
- data/spec/runner_spec.rb +23 -22
- data/spec/spec_helper.rb +61 -58
- data/spec/templates_spec.rb +52 -52
- data/spec/views/layout.erb +6 -6
- metadata +27 -12
- data/lib/nyny/middleware_chain.rb +0 -14
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,105 +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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
response.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
response.
|
97
|
-
response.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
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
|
data/spec/router_spec.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Router do
|
4
|
-
let (:app) do
|
5
|
-
mock_app do
|
6
|
-
get '/' do
|
7
|
-
halt 200, {}, "Bar"
|
8
|
-
"Foo"
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
response.body = "Zaz"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should eval after blocks even if the request was halted" do
|
18
|
-
response = app.get('/')
|
19
|
-
response.body.should == "Zaz"
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Router do
|
4
|
+
let (:app) do
|
5
|
+
mock_app do
|
6
|
+
get '/' do
|
7
|
+
halt 200, {}, "Bar"
|
8
|
+
"Foo"
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
response.body = "Zaz"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should eval after blocks even if the request was halted" do
|
18
|
+
response = app.get('/')
|
19
|
+
response.body.should == "Zaz"
|
20
|
+
end
|
21
|
+
end
|
data/spec/runner_spec.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Runner do
|
4
|
-
let (:kls) { mock_app_class {} }
|
5
|
-
|
6
|
-
before do
|
7
|
-
kls.optimal_runner.stub :run
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should include the default middleware on top' do
|
11
|
-
kls.
|
12
|
-
kls.
|
13
|
-
kls.
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should not include show exceptions middleware in production' do
|
17
|
-
NYNY.env.stub :production? => true
|
18
|
-
kls.
|
19
|
-
kls.
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Runner do
|
4
|
+
let (:kls) { mock_app_class {} }
|
5
|
+
|
6
|
+
before do
|
7
|
+
kls.optimal_runner.stub :run
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should include the default middleware on top' do
|
11
|
+
kls.should_receive(:use).with(Rack::CommonLogger)
|
12
|
+
kls.should_receive(:use).with(Rack::ShowExceptions)
|
13
|
+
kls.run!
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not include show exceptions middleware in production' do
|
17
|
+
NYNY.env.stub :production? => true
|
18
|
+
kls.should_receive(:use).with(Rack::CommonLogger)
|
19
|
+
kls.should_not_receive(:use).with(Rack::ShowExceptions)
|
20
|
+
kls.run!
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,58 +1,61 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
1
|
+
require 'securerandom'
|
2
|
+
ENV['RACK_ENV'] = 'test'
|
3
|
+
|
4
|
+
if ENV['TRAVIS']
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
else
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "spec"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'nyny'
|
15
|
+
include NYNY
|
16
|
+
|
17
|
+
class Rack::MockRequest
|
18
|
+
def trace(uri, opts={}) request("TRACE", uri, opts) end
|
19
|
+
def options(uri, opts={}) request("OPTIONS", uri, opts) end
|
20
|
+
end
|
21
|
+
|
22
|
+
def template name
|
23
|
+
File.join(File.dirname(__FILE__), 'views', name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extended_modules_for kls
|
27
|
+
(class << kls; self end).included_modules
|
28
|
+
end
|
29
|
+
|
30
|
+
def mock_app parent=App, &blk
|
31
|
+
Rack::MockRequest.new mock_app_class(parent, &blk).new
|
32
|
+
end
|
33
|
+
|
34
|
+
def mock_app_class parent=App, &blk
|
35
|
+
Class.new(parent, &blk)
|
36
|
+
end
|
37
|
+
|
38
|
+
def random_url levels=1
|
39
|
+
parts = levels.times.map do
|
40
|
+
SecureRandom.urlsafe_base64
|
41
|
+
end
|
42
|
+
|
43
|
+
"/#{parts.join('/')}"
|
44
|
+
end
|
45
|
+
|
46
|
+
class NullMiddleware
|
47
|
+
def initialize app
|
48
|
+
@app = app
|
49
|
+
end
|
50
|
+
|
51
|
+
def call env
|
52
|
+
@app.call env
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module NullHelper
|
57
|
+
end
|
58
|
+
|
59
|
+
RSpec.configure do |c|
|
60
|
+
c.filter_run_excluding :broken => true
|
61
|
+
end
|