nyny 3.0.0 → 3.0.1
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 -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/router_spec.rb
CHANGED
@@ -1,21 +1,29 @@
|
|
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
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
post '/' do
|
12
|
+
params[:not_exist].to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
response.body = "Zaz"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should eval after blocks even if the request was halted" do
|
22
|
+
response = app.get('/')
|
23
|
+
response.body.should == "Zaz"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not raise SystemStackError if any absent param is accessed" do
|
27
|
+
expect { response = app.post('/') }.not_to raise_error SystemStackError
|
28
|
+
end
|
29
|
+
end
|
data/spec/runner_spec.rb
CHANGED
@@ -1,23 +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.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
|
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,61 +1,61 @@
|
|
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
|
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
|
data/spec/templates_spec.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Templates do
|
4
|
-
let (:app) do
|
5
|
-
mock_app do
|
6
|
-
get '/without_layout' do
|
7
|
-
render template('index.erb')
|
8
|
-
end
|
9
|
-
|
10
|
-
get '/with_layout' do
|
11
|
-
render template('layout.erb') do
|
12
|
-
render template('index.erb')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
get '/instance_var' do
|
17
|
-
@foo = 'bar'
|
18
|
-
render template('instance.erb')
|
19
|
-
end
|
20
|
-
|
21
|
-
get '/local_var' do
|
22
|
-
render template('local.erb'), :foo => 'bar'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'renders correctly without layout' do
|
28
|
-
response = app.get('/without_layout')
|
29
|
-
response.body.should == '<p>Hello!</p>'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'passes a instance variable to template' do
|
33
|
-
response = app.get('/instance_var')
|
34
|
-
response.body.should == 'bar'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'passes a local variable to template' do
|
38
|
-
response = app.get('/local_var')
|
39
|
-
response.body.should == 'bar'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'renders correctly with layout' do
|
43
|
-
response = app.get('/with_layout')
|
44
|
-
|
45
|
-
rendered = Tilt.new(template('layout.erb')).render do
|
46
|
-
Tilt.new(template('index.erb')).render
|
47
|
-
end
|
48
|
-
|
49
|
-
response.body.should == rendered
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Templates do
|
4
|
+
let (:app) do
|
5
|
+
mock_app do
|
6
|
+
get '/without_layout' do
|
7
|
+
render template('index.erb')
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/with_layout' do
|
11
|
+
render template('layout.erb') do
|
12
|
+
render template('index.erb')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/instance_var' do
|
17
|
+
@foo = 'bar'
|
18
|
+
render template('instance.erb')
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/local_var' do
|
22
|
+
render template('local.erb'), :foo => 'bar'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'renders correctly without layout' do
|
28
|
+
response = app.get('/without_layout')
|
29
|
+
response.body.should == '<p>Hello!</p>'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'passes a instance variable to template' do
|
33
|
+
response = app.get('/instance_var')
|
34
|
+
response.body.should == 'bar'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'passes a local variable to template' do
|
38
|
+
response = app.get('/local_var')
|
39
|
+
response.body.should == 'bar'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'renders correctly with layout' do
|
43
|
+
response = app.get('/with_layout')
|
44
|
+
|
45
|
+
rendered = Tilt.new(template('layout.erb')).render do
|
46
|
+
Tilt.new(template('index.erb')).render
|
47
|
+
end
|
48
|
+
|
49
|
+
response.body.should == rendered
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/views/layout.erb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html>
|
3
|
-
<head></head>
|
4
|
-
<body>
|
5
|
-
<%= yield %>
|
6
|
-
</body>
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head></head>
|
4
|
+
<body>
|
5
|
+
<%= yield %>
|
6
|
+
</body>
|
7
7
|
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Lisnic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - '>='
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 1.9.2
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - '>='
|