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.
@@ -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
- child_helper.should == :child
42
- end
43
-
44
- get '/child' do
45
- 'child'
46
- end
47
- end
48
-
49
- let (:parent) { Rack::MockRequest.new Parent.new }
50
- let (:child) { Rack::MockRequest.new Child.new }
51
-
52
- it 'works correctly for routes' do
53
- parent.get('/parent').body.should == 'parent'
54
- parent.get('/child').status.should == 404
55
- child.get('/parent').body.should == 'parent'
56
- child.get('/child').body.should == 'child'
57
- end
58
-
59
- it 'works correctly for before filters' do
60
- parent.get('/parent').headers['child before'].should be_nil
61
- child.get('/parent').headers['child before'].should_not be_nil
62
- child.get('/parent').headers['parent before'].should_not be_nil
63
- end
64
-
65
- it 'works correctly for after filters' do
66
- parent.get('/parent').headers['child after'].should be_nil
67
- child.get('/parent').headers['child after'].should_not be_nil
68
- child.get('/parent').headers['parent after'].should_not be_nil
69
- end
70
-
71
- it 'works correctly for helpers' do
72
- parent.get('/helpers')
73
- child.get('/helpers')
74
- end
75
- end
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
@@ -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,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