nyny 1.0.0.pre1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
- require_relative 'spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Request do
4
- let (:subject) { Request.new stub }
4
+ let (:subject) { Request.new double }
5
5
 
6
6
  it { should be_a(Rack::Request) }
7
7
  end
@@ -11,14 +11,21 @@ describe Response do
11
11
 
12
12
  describe '#raw_body' do
13
13
  it 'should be accesible when the response was initialized' do
14
- raw_body = stub
14
+ raw_body = double
15
15
  res = Response.new raw_body
16
16
  res.raw_body.should == raw_body
17
17
  end
18
18
 
19
19
  it 'should accesible after body was set' do
20
20
  res = Response.new
21
- raw_body = stub
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']
22
29
  res.body = raw_body
23
30
  res.raw_body.should == raw_body
24
31
  end
@@ -1,9 +1,9 @@
1
- require_relative 'spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe RequestScope do
4
4
  let (:env) { Rack::MockRequest.env_for '/', :params => {:some => 'param'} }
5
5
  let (:dummy_request) { Rack::Request.new(env) }
6
- let (:subject) { RequestScope.new App.new, dummy_request }
6
+ let (:subject) { RequestScope.new dummy_request }
7
7
  let (:handler) {
8
8
  Proc.new {"hello"}
9
9
  }
@@ -18,6 +18,16 @@ describe RequestScope do
18
18
  its (:cookies) { should == dummy_request.cookies }
19
19
  its (:session) { should == dummy_request.session }
20
20
 
21
+ it 'params should have insensitive keys' do
22
+ app = mock_app do
23
+ get '/' do
24
+ params[:foo].should == params['foo']
25
+ end
26
+ end
27
+
28
+ app.get '/?foo=bar'
29
+ end
30
+
21
31
  it '#headers should set the header values' do
22
32
  subject.headers 'Head' => 'Tail'
23
33
  response = subject.apply_to &handler
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe RouteSignature do
4
+ it 'should have the initial regexp as the pattern' do
5
+ exp = /[w+]/
6
+ sig = RouteSignature.new exp
7
+ sig.pattern.should == exp
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Runner do
4
+ describe '.run!' do
5
+ before do
6
+ handler = begin
7
+ Rack::Handler::Thin
8
+ rescue LoadError
9
+ Rack::Handler::WEBrick
10
+ end
11
+ handler.stub :run
12
+ end
13
+
14
+ it 'should include the default middleware on top' do
15
+ kls = mock_app_class do
16
+ end
17
+
18
+ kls.run!
19
+ kls.middlewares.first.should == Rack::ShowExceptions
20
+ kls.middlewares[1].should == Rack::CommonLogger
21
+ end
22
+ end
23
+ end
@@ -1,6 +1,17 @@
1
- require 'nyny'
2
1
  require 'rack'
3
2
  require 'securerandom'
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'
4
15
  include NYNY
5
16
 
6
17
  class Rack::MockRequest
@@ -13,10 +24,10 @@ def extended_modules_for kls
13
24
  end
14
25
 
15
26
  def mock_app &blk
16
- Rack::MockRequest.new frankie_app(&blk).new
27
+ Rack::MockRequest.new mock_app_class(&blk).new
17
28
  end
18
29
 
19
- def frankie_app &blk
30
+ def mock_app_class &blk
20
31
  Class.new(App, &blk)
21
32
  end
22
33
 
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: 1.0.0.pre1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Lisnic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-22 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: New York, New York.
55
+ description: New York, New York - (very) small Sinatra clone.
56
56
  email:
57
57
  - andrei.lisnic@gmail.com
58
58
  executables: []
@@ -61,20 +61,20 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
63
  - .rspec
64
- - .ruby-gemset
65
64
  - .ruby-version
65
+ - .travis.yml
66
66
  - Gemfile
67
67
  - LICENSE.txt
68
68
  - Performance.md
69
69
  - README.md
70
70
  - Rakefile
71
- - benchmarks/filters/frankie.rb
71
+ - benchmarks/filters/nyny.rb
72
72
  - benchmarks/filters/sinatra.rb
73
- - benchmarks/helpers/frankie.rb
73
+ - benchmarks/helpers/nyny.rb
74
74
  - benchmarks/helpers/sinatra.rb
75
- - benchmarks/simple/frankie.rb
75
+ - benchmarks/simple/nyny.rb
76
76
  - benchmarks/simple/sinatra.rb
77
- - benchmarks/url_pattern/frankie.rb
77
+ - benchmarks/url_pattern/nyny.rb
78
78
  - benchmarks/url_pattern/sinatra.rb
79
79
  - examples/active_record/.gitignore
80
80
  - examples/active_record/Gemfile
@@ -84,6 +84,10 @@ files:
84
84
  - examples/active_record/db/migrate/20130606133756_add_shouts.rb
85
85
  - examples/active_record/models/shout.rb
86
86
  - examples/active_record/server.rb
87
+ - examples/data_mapper/Gemfile
88
+ - examples/data_mapper/database.rb
89
+ - examples/data_mapper/models/shout.rb
90
+ - examples/data_mapper/server.rb
87
91
  - examples/json_api.rb
88
92
  - examples/templates/server.rb
89
93
  - examples/templates/views/index.haml
@@ -95,16 +99,19 @@ files:
95
99
  - examples/web_sockets/server.rb
96
100
  - lib/nyny.rb
97
101
  - lib/nyny/app.rb
98
- - lib/nyny/class_level_api.rb
102
+ - lib/nyny/middleware_chain.rb
99
103
  - lib/nyny/primitives.rb
100
104
  - lib/nyny/request_scope.rb
101
105
  - lib/nyny/route_signature.rb
106
+ - lib/nyny/router.rb
107
+ - lib/nyny/runner.rb
102
108
  - lib/nyny/version.rb
103
109
  - nyny.gemspec
104
110
  - spec/app_spec.rb
105
- - spec/class_level_api_spec.rb
106
111
  - spec/primitives_spec.rb
107
112
  - spec/request_scope_spec.rb
113
+ - spec/route_signature_spec.rb
114
+ - spec/runner_spec.rb
108
115
  - spec/spec_helper.rb
109
116
  homepage: https://github.com/alisnic/nyny
110
117
  licenses:
@@ -121,18 +128,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
128
  version: '0'
122
129
  required_rubygems_version: !ruby/object:Gem::Requirement
123
130
  requirements:
124
- - - '>'
131
+ - - '>='
125
132
  - !ruby/object:Gem::Version
126
- version: 1.3.1
133
+ version: '0'
127
134
  requirements: []
128
135
  rubyforge_project:
129
- rubygems_version: 2.0.2
136
+ rubygems_version: 2.0.3
130
137
  signing_key:
131
138
  specification_version: 4
132
- summary: sinatra's little brother
139
+ summary: New York, New York.
133
140
  test_files:
134
141
  - spec/app_spec.rb
135
- - spec/class_level_api_spec.rb
136
142
  - spec/primitives_spec.rb
137
143
  - spec/request_scope_spec.rb
144
+ - spec/route_signature_spec.rb
145
+ - spec/runner_spec.rb
138
146
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- frankie
@@ -1,40 +0,0 @@
1
- module NYNY
2
- module ClassLevelApi
3
- HTTP_VERBS = [:delete, :get, :head, :options, :patch, :post, :put, :trace]
4
- HTTP_VERBS.each do |method|
5
- define_method method do |str, &blk|
6
- (routes[method] ||= {})[RouteSignature.new(str)] = Proc.new &blk
7
- end
8
- end
9
-
10
- def middlewares; @middlewares ||= [] end
11
- def routes; @routes ||= {} end
12
- def before_hooks; @before_hooks ||= [] end
13
- def after_hooks; @after_hooks ||= [] end
14
-
15
- def use_protection! args={}
16
- begin
17
- require 'rack/protection'
18
- middlewares.unshift [Rack::Protection, args]
19
- rescue LoadError
20
- puts "WARN: to use protection, you must install 'rack-protection' gem"
21
- end
22
- end
23
-
24
- def before &blk
25
- before_hooks << Proc.new(&blk)
26
- end
27
-
28
- def after &blk
29
- after_hooks << Proc.new(&blk)
30
- end
31
-
32
- def use middleware, *args, &block
33
- middlewares << [middleware, args, block]
34
- end
35
-
36
- def helpers *args
37
- args.each {|m| RequestScope.add_helper_module m }
38
- end
39
- end
40
- end
@@ -1,39 +0,0 @@
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