nyny 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -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
- 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 '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
-
31
- it '#headers should set the header values' do
32
- subject.headers 'Head' => 'Tail'
33
- response = subject.apply_to &handler
34
- response.headers['Head'].should == 'Tail'
35
- end
36
-
37
- it '#status should set the response status' do
38
- forbid = Proc.new { status 403 }
39
- response = subject.apply_to &forbid
40
- response.status.should == 403
41
- end
42
-
43
- it 'params should have insensitive keys' do
44
- app = mock_app do
45
- get '/' do
46
- params[:foo].should == params['foo']
47
- end
48
- end
49
-
50
- app.get '/?foo=bar'
51
- end
52
-
53
- it 'halt in a before block should override the response' do
54
- prc = Proc.new { 'da block' }
55
-
56
- app = mock_app do
57
- before do
58
- halt 302
59
- end
60
-
61
- get '/', &prc
62
- end
63
-
64
- res = app.get '/'
65
- res.status.should == 302
66
- prc.should_not_receive(:call)
67
- end
68
-
69
- it 'should halt if the statement is in the route definition' do
70
- app = mock_app do
71
- get '/' do
72
- halt 200, {}, 'Halted'
73
- 'shouldnt be returned'
74
- end
75
- end
76
- res = app.get '/'
77
- res.status.should == 200
78
- res.body.should == 'Halted'
79
- end
80
-
81
- it 'return prematurely with pass' do
82
- app = mock_app do
83
- get '/' do
84
- next 'hui'
85
- 'shouldnt be returned'
86
- end
87
- end
88
- res = app.get '/'
89
- res.status.should == 200
90
- res.body.should == 'hui'
91
- end
92
-
93
- it '#redirect_to should redirect' do
94
- redir = Proc.new { redirect_to 'http://foo.bar' }
95
- response = catch(:halt) { subject.apply_to &redir }
96
- response.status.should == 302
97
- response.headers['Location'].should == 'http://foo.bar'
98
- end
99
-
100
- it '#apply_to should return a Rack response' do
101
- response = subject.apply_to &handler
102
- response.should be_a(Rack::Response)
103
- end
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.run!
12
- kls.middlewares.first.should == Rack::ShowExceptions
13
- kls.middlewares[1].should == Rack::CommonLogger
14
- end
15
-
16
- it 'should not include show exceptions middleware in production' do
17
- NYNY.env.stub :production? => true
18
- kls.run!
19
- kls.middlewares.should == [Rack::CommonLogger]
20
- end
21
-
22
- 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,58 +1,61 @@
1
- require 'rack'
2
- require 'securerandom'
3
- ENV['RACK_ENV'] = 'test'
4
-
5
- if ENV['TRAVIS']
6
- require 'coveralls'
7
- Coveralls.wear!
8
- else
9
- require 'simplecov'
10
- SimpleCov.start do
11
- add_filter "spec"
12
- end
13
- end
14
-
15
- require 'nyny'
16
- include NYNY
17
-
18
- class Rack::MockRequest
19
- def trace(uri, opts={}) request("TRACE", uri, opts) end
20
- def options(uri, opts={}) request("OPTIONS", uri, opts) end
21
- end
22
-
23
- def template name
24
- File.join(File.dirname(__FILE__), 'views', name)
25
- end
26
-
27
- def extended_modules_for kls
28
- (class << kls; self end).included_modules
29
- end
30
-
31
- def mock_app &blk
32
- Rack::MockRequest.new mock_app_class(&blk).new
33
- end
34
-
35
- def mock_app_class &blk
36
- Class.new(App, &blk)
37
- end
38
-
39
- def random_url levels=1
40
- parts = levels.times.map do
41
- SecureRandom.urlsafe_base64
42
- end
43
-
44
- "/#{parts.join('/')}"
45
- end
46
-
47
- class NullMiddleware
48
- def initialize app
49
- @app = app
50
- end
51
-
52
- def call env
53
- @app.call env
54
- end
55
- end
56
-
57
- module NullHelper
58
- 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