mojito 0.1.0 → 0.1.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.
- data/README.textile +1 -1
- data/VERSION +1 -1
- data/lib/mojito.rb +5 -0
- data/lib/mojito/base.rb +1 -0
- data/lib/mojito/helpers/exception_handling.rb +1 -1
- data/lib/mojito/matchers.rb +7 -0
- data/lib/mojito/matchers/environment.rb +13 -0
- data/lib/mojito/matchers/path.rb +2 -2
- data/lib/mojito/matchers/session.rb +13 -0
- data/lib/mojito/matchers/url_scheme.rb +22 -0
- data/lib/mojito/rendering.rb +2 -0
- data/lib/mojito/rendering/templates.rb +26 -0
- data/spec/mojito/matchers/methods_spec.rb +27 -0
- data/spec/mojito/matchers/path_spec.rb +74 -0
- data/spec/mojito/matchers/session_spec.rb +7 -0
- data/spec/mojito/matchers/url_scheme_spec.rb +22 -0
- data/spec/mojito/matchers/virtual_host_spec.rb +22 -0
- data/spec/mojito/matchers_spec.rb +0 -108
- data/spec/mojito/rendering/content_spec.rb +17 -0
- data/spec/mojito/rendering/delegation_spec.rb +37 -0
- data/spec/mojito/rendering/file_spec.rb +24 -0
- data/spec/mojito/rendering/status_codes_spec.rb +26 -0
- data/spec/mojito/rendering/templates_spec.rb +37 -0
- data/spec/mojito/rendering_spec.rb +0 -84
- metadata +45 -20
data/README.textile
CHANGED
@@ -2,7 +2,7 @@ h1. mojito - Next level Ruby webframework
|
|
2
2
|
|
3
3
|
p. Mojito is a lean and simple webframework.
|
4
4
|
|
5
|
-
p. As the name implies mojito
|
5
|
+
p. As the name implies mojito derives from cuba (https://github.com/soveran/cuba). Many thanks to Michel and his cuba project for giving me some major insights on web-application-simplicity!
|
6
6
|
|
7
7
|
h2. Installing
|
8
8
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/mojito.rb
CHANGED
data/lib/mojito/base.rb
CHANGED
@@ -50,13 +50,13 @@ module Mojito
|
|
50
50
|
def __handle_error(exception)
|
51
51
|
if handler = case exception
|
52
52
|
when MojitoException
|
53
|
+
response.status = exception.status
|
53
54
|
self.class.error_handlers[exception.status]
|
54
55
|
when Exception
|
55
56
|
self.class.error_handlers[exception.class]
|
56
57
|
end
|
57
58
|
instance_exec &handler
|
58
59
|
end
|
59
|
-
puts "Exception: #{exception.inspect}"
|
60
60
|
raise exception
|
61
61
|
end
|
62
62
|
|
data/lib/mojito/matchers.rb
CHANGED
@@ -2,15 +2,22 @@
|
|
2
2
|
|
3
3
|
module Mojito::Matchers
|
4
4
|
|
5
|
+
require 'mojito/matchers/environment'
|
5
6
|
require 'mojito/matchers/methods'
|
6
7
|
require 'mojito/matchers/path'
|
8
|
+
require 'mojito/matchers/url_scheme'
|
7
9
|
require 'mojito/matchers/virtual_host'
|
8
10
|
|
11
|
+
include Environment
|
9
12
|
include Methods
|
10
13
|
include Path
|
14
|
+
include UrlScheme
|
11
15
|
include VirtualHost
|
12
16
|
|
17
|
+
extend Environment
|
18
|
+
extend Methods
|
13
19
|
extend Path
|
20
|
+
extend UrlScheme
|
14
21
|
extend VirtualHost
|
15
22
|
|
16
23
|
end
|
data/lib/mojito/matchers/path.rb
CHANGED
@@ -6,7 +6,7 @@ module Mojito::Matchers
|
|
6
6
|
|
7
7
|
def PATH(pattern)
|
8
8
|
consume_path = proc do |pattern|
|
9
|
-
if match = env['PATH_INFO'].match(%r<\A
|
9
|
+
if match = env['PATH_INFO'].match(%r<\A/*#{pattern}(?=/|\z)>)
|
10
10
|
env['SCRIPT_NAME'] = match.to_s
|
11
11
|
env['PATH_INFO'] = match.post_match
|
12
12
|
request.locals.update match.names.inject({}) {|hash, name| hash[name.to_sym] = match[name] ; hash }
|
@@ -23,7 +23,7 @@ module Mojito::Matchers
|
|
23
23
|
when Regexp
|
24
24
|
pattern
|
25
25
|
end
|
26
|
-
instance_exec p,
|
26
|
+
instance_exec p, &consume_path
|
27
27
|
else
|
28
28
|
false
|
29
29
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Mojito::Matchers
|
4
|
+
|
5
|
+
module UrlScheme
|
6
|
+
|
7
|
+
def SCHEME(scheme)
|
8
|
+
proc do
|
9
|
+
case scheme
|
10
|
+
when :https, :secure
|
11
|
+
request.scheme === 'https'
|
12
|
+
when :http, nil
|
13
|
+
request.scheme === 'http'
|
14
|
+
else
|
15
|
+
request.scheme === scheme.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/mojito/rendering.rb
CHANGED
@@ -7,11 +7,13 @@ module Mojito::Rendering
|
|
7
7
|
require 'mojito/rendering/delegation'
|
8
8
|
require 'mojito/rendering/file'
|
9
9
|
require 'mojito/rendering/status_codes'
|
10
|
+
require 'mojito/rendering/templates'
|
10
11
|
|
11
12
|
include Content
|
12
13
|
include ContentTypes
|
13
14
|
include Delegation
|
14
15
|
include File
|
15
16
|
include StatusCodes
|
17
|
+
include Templates
|
16
18
|
|
17
19
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Mojito::Rendering
|
4
|
+
|
5
|
+
module Templates
|
6
|
+
require 'tilt'
|
7
|
+
require 'where'
|
8
|
+
require 'mime/types'
|
9
|
+
|
10
|
+
def template(*args, &block)
|
11
|
+
locals = Hash === args.last ? args.pop : self.locals
|
12
|
+
template = if args.size == 2
|
13
|
+
Tilt[args.first].new { args.last }
|
14
|
+
elsif args.size == 1
|
15
|
+
file = Where.cdir(1) + args.first
|
16
|
+
if %r{\.(?<extension>\w+)\.\w+$} =~ file.to_s
|
17
|
+
response['Content-Type'] = MIME::Types.type_for(extension)
|
18
|
+
end
|
19
|
+
Tilt[file.to_s].new file.to_s
|
20
|
+
end
|
21
|
+
response.write template.render(self, locals, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Matchers::Methods do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.application Mojito::Matchers::Methods do
|
11
|
+
on GET() do write 'get' ; halt! end
|
12
|
+
on POST() do write 'post' ; halt! end
|
13
|
+
on HEAD() do write 'head' ; halt! end
|
14
|
+
on PUT() do write 'put' ; halt! end
|
15
|
+
on DELETE() do write 'delete' ; halt! end
|
16
|
+
on METHOD(:options) do write 'options' ; halt! end
|
17
|
+
end.mock_request
|
18
|
+
end
|
19
|
+
|
20
|
+
it { subject.get('/').body.should == 'get' }
|
21
|
+
it { subject.post('/').body.should == 'post' }
|
22
|
+
it { subject.head('/').body.should == 'head' }
|
23
|
+
it { subject.put('/').body.should == 'put' }
|
24
|
+
it { subject.delete('/').body.should == 'delete' }
|
25
|
+
it { subject.request('OPTIONS', '/').body.should == 'options' }
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Matchers::Path do
|
8
|
+
|
9
|
+
subject { Mojito.application.new Rack::MockRequest.env_for('http://localhost/hello/world/rest') }
|
10
|
+
|
11
|
+
it do
|
12
|
+
subject.send(:__match?, Mojito::M::PATH('hello'))
|
13
|
+
subject.captures.should be_empty
|
14
|
+
subject.locals.should be_empty
|
15
|
+
subject.path_info.should == '/world/rest'
|
16
|
+
end
|
17
|
+
|
18
|
+
it do
|
19
|
+
subject.send(:__match?, 'hello')
|
20
|
+
subject.captures.should be_empty
|
21
|
+
subject.locals.should be_empty
|
22
|
+
subject.path_info.should == '/world/rest'
|
23
|
+
end
|
24
|
+
|
25
|
+
it do
|
26
|
+
subject.send(:__match?, Mojito::M::PATH('hello/:name'))
|
27
|
+
subject.request.captures.should == ['world']
|
28
|
+
subject.request.locals.should == { 'name' => 'world' }
|
29
|
+
subject.request.path_info.should == '/rest'
|
30
|
+
end
|
31
|
+
|
32
|
+
it do
|
33
|
+
subject.send(:__match?, 'hello/:name')
|
34
|
+
subject.request.captures.should == ['world']
|
35
|
+
subject.request.locals.should == { 'name' => 'world' }
|
36
|
+
subject.request.path_info.should == '/rest'
|
37
|
+
end
|
38
|
+
|
39
|
+
it do
|
40
|
+
subject.send(:__match?, Mojito::M::PATH(%r{hello/(?<name>[^/]+)}))
|
41
|
+
subject.request.captures.should == ['world']
|
42
|
+
subject.request.locals.should == { 'name' => 'world' }
|
43
|
+
subject.request.path_info.should == '/rest'
|
44
|
+
end
|
45
|
+
|
46
|
+
it do
|
47
|
+
subject.send(:__match?, %r{hello/(?<name>[^/]+)})
|
48
|
+
subject.request.captures.should == ['world']
|
49
|
+
subject.request.locals.should == { 'name' => 'world' }
|
50
|
+
subject.request.path_info.should == '/rest'
|
51
|
+
end
|
52
|
+
|
53
|
+
context do
|
54
|
+
subject do
|
55
|
+
Mojito.base_application Mojito::M::Path, Mojito::R::Content do
|
56
|
+
on PATH('hello/:name') do
|
57
|
+
on PATH('another/:name') do
|
58
|
+
write request.locals[:name]
|
59
|
+
halt!
|
60
|
+
end
|
61
|
+
write request.locals[:name]
|
62
|
+
halt!
|
63
|
+
end
|
64
|
+
end.mock_request
|
65
|
+
end
|
66
|
+
|
67
|
+
it { subject.get('/hello/Fred').status.should == 200 }
|
68
|
+
it { subject.get('/hello/Fred').body.should == 'Fred' }
|
69
|
+
it { subject.get('/hello/Fred/another/Barney').status.should == 200 }
|
70
|
+
it { subject.get('/hello/Fred/another/Barney').body.should == 'Barney' }
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Matchers::UrlScheme do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.application Mojito::Matchers::UrlScheme do
|
11
|
+
on SCHEME(:http) do write 'insecure' ; halt! end
|
12
|
+
on SCHEME(:https) do write 'secure' ; halt! end
|
13
|
+
end.mock_request
|
14
|
+
end
|
15
|
+
|
16
|
+
it { subject.get('http://localhost/').body.should == 'insecure' }
|
17
|
+
it { subject.get('http://localhost:7777/').body.should == 'insecure' }
|
18
|
+
it { subject.get('https://localhost:80/').body.should == 'secure' }
|
19
|
+
it { subject.get('https://localhost/').body.should == 'secure' }
|
20
|
+
it { subject.get('otherprotocol://test/').status.should == 404 }
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Matchers::VirtualHost do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.application Mojito::Matchers::VirtualHost do
|
11
|
+
on HOST('localhost') do write 'localhost' ; halt! end
|
12
|
+
on HOST('test:8080') do write 'test' ; halt! end
|
13
|
+
end.mock_request
|
14
|
+
end
|
15
|
+
|
16
|
+
it { subject.get('http://localhost:4444/').body.should == 'localhost' }
|
17
|
+
it { subject.get('http://localhost/').body.should == 'localhost' }
|
18
|
+
it { subject.get('http://localhost:80/').body.should == 'localhost' }
|
19
|
+
it { subject.get('http://test:8080/').body.should == 'test' }
|
20
|
+
it { subject.get('http://test/').status.should == 404 }
|
21
|
+
|
22
|
+
end
|
@@ -3,111 +3,3 @@ require 'simplecov' and SimpleCov.start do
|
|
3
3
|
add_filter "spec/"
|
4
4
|
end
|
5
5
|
require 'mojito'
|
6
|
-
|
7
|
-
describe Mojito::Matchers::Methods do
|
8
|
-
|
9
|
-
subject do
|
10
|
-
Mojito.application Mojito::Matchers::Methods do
|
11
|
-
on GET() do write 'get' ; halt! end
|
12
|
-
on POST() do write 'post' ; halt! end
|
13
|
-
on HEAD() do write 'head' ; halt! end
|
14
|
-
on PUT() do write 'put' ; halt! end
|
15
|
-
on DELETE() do write 'delete' ; halt! end
|
16
|
-
on METHOD(:options) do write 'options' ; halt! end
|
17
|
-
end.mock_request
|
18
|
-
end
|
19
|
-
|
20
|
-
it { subject.get('/').body.should == 'get' }
|
21
|
-
it { subject.post('/').body.should == 'post' }
|
22
|
-
it { subject.head('/').body.should == 'head' }
|
23
|
-
it { subject.put('/').body.should == 'put' }
|
24
|
-
it { subject.delete('/').body.should == 'delete' }
|
25
|
-
it { subject.request('OPTIONS', '/').body.should == 'options' }
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
describe Mojito::Matchers::Path do
|
30
|
-
|
31
|
-
subject { Mojito.application.new Rack::MockRequest.env_for('http://localhost/hello/world/rest') }
|
32
|
-
|
33
|
-
it do
|
34
|
-
subject.send(:__match?, Mojito::M::PATH('hello'))
|
35
|
-
subject.captures.should be_empty
|
36
|
-
subject.locals.should be_empty
|
37
|
-
subject.path_info.should == '/world/rest'
|
38
|
-
end
|
39
|
-
|
40
|
-
it do
|
41
|
-
subject.send(:__match?, 'hello')
|
42
|
-
subject.captures.should be_empty
|
43
|
-
subject.locals.should be_empty
|
44
|
-
subject.path_info.should == '/world/rest'
|
45
|
-
end
|
46
|
-
|
47
|
-
it do
|
48
|
-
subject.send(:__match?, Mojito::M::PATH('hello/:name'))
|
49
|
-
subject.request.captures.should == ['world']
|
50
|
-
subject.request.locals.should == { 'name' => 'world' }
|
51
|
-
subject.request.path_info.should == '/rest'
|
52
|
-
end
|
53
|
-
|
54
|
-
it do
|
55
|
-
subject.send(:__match?, 'hello/:name')
|
56
|
-
subject.request.captures.should == ['world']
|
57
|
-
subject.request.locals.should == { 'name' => 'world' }
|
58
|
-
subject.request.path_info.should == '/rest'
|
59
|
-
end
|
60
|
-
|
61
|
-
it do
|
62
|
-
subject.send(:__match?, Mojito::M::PATH(%r{hello/(?<name>[^/]+)}))
|
63
|
-
subject.request.captures.should == ['world']
|
64
|
-
subject.request.locals.should == { 'name' => 'world' }
|
65
|
-
subject.request.path_info.should == '/rest'
|
66
|
-
end
|
67
|
-
|
68
|
-
it do
|
69
|
-
subject.send(:__match?, %r{hello/(?<name>[^/]+)})
|
70
|
-
subject.request.captures.should == ['world']
|
71
|
-
subject.request.locals.should == { 'name' => 'world' }
|
72
|
-
subject.request.path_info.should == '/rest'
|
73
|
-
end
|
74
|
-
|
75
|
-
context do
|
76
|
-
subject do
|
77
|
-
Mojito.base_application Mojito::M::Path, Mojito::R::Content do
|
78
|
-
on PATH('hello/:name') do
|
79
|
-
on PATH('another/:name') do
|
80
|
-
write request.locals[:name]
|
81
|
-
halt!
|
82
|
-
end
|
83
|
-
write request.locals[:name]
|
84
|
-
halt!
|
85
|
-
end
|
86
|
-
end.mock_request
|
87
|
-
end
|
88
|
-
|
89
|
-
it { subject.get('/hello/Fred').status.should == 200 }
|
90
|
-
it { subject.get('/hello/Fred').body.should == 'Fred' }
|
91
|
-
it { subject.get('/hello/Fred/another/Barney').status.should == 200 }
|
92
|
-
it { subject.get('/hello/Fred/another/Barney').body.should == 'Barney' }
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
describe Mojito::Matchers::VirtualHost do
|
99
|
-
|
100
|
-
subject do
|
101
|
-
Mojito.application Mojito::Matchers::VirtualHost do
|
102
|
-
on HOST('localhost') do write 'localhost' ; halt! end
|
103
|
-
on HOST('test:8080') do write 'test' ; halt! end
|
104
|
-
end.mock_request
|
105
|
-
end
|
106
|
-
|
107
|
-
it { subject.get('http://localhost:4444/').body.should == 'localhost' }
|
108
|
-
it { subject.get('http://localhost/').body.should == 'localhost' }
|
109
|
-
it { subject.get('http://localhost:80/').body.should == 'localhost' }
|
110
|
-
it { subject.get('http://test:8080/').body.should == 'test' }
|
111
|
-
it { subject.get('http://test/').status.should == 404 }
|
112
|
-
|
113
|
-
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Rendering::Content do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.base_application Mojito::Rendering::Content do
|
11
|
+
on do write 'test content' ; halt! end
|
12
|
+
end.mock_request
|
13
|
+
end
|
14
|
+
|
15
|
+
it { subject.get('/').body.should == 'test content' }
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Rendering::Delegation do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
sub_app = Mojito.base_application Mojito::R::Content, Mojito::R::Delegation do
|
11
|
+
on true do write 'sub-application' ; halt! end
|
12
|
+
end
|
13
|
+
Mojito.base_application Mojito::Rendering::Content, Mojito::Rendering::Delegation do
|
14
|
+
on true do run! sub_app end
|
15
|
+
end.mock_request
|
16
|
+
end
|
17
|
+
|
18
|
+
it { subject.get('/').status.should == 200 }
|
19
|
+
it { subject.get('/').body.should == 'sub-application' }
|
20
|
+
|
21
|
+
context do
|
22
|
+
|
23
|
+
subject do
|
24
|
+
sub_app = Mojito.base_application Mojito::R::Content, Mojito::R::Delegation, Mojito::H::Shortcuts do
|
25
|
+
on true do write("#{path_info} #{captures.first}") ; halt! end
|
26
|
+
end
|
27
|
+
Mojito.base_application Mojito::M::Path, Mojito::R::Content, Mojito::R::Delegation do
|
28
|
+
on PATH('hello/:name') do run! sub_app end
|
29
|
+
end.mock_request
|
30
|
+
end
|
31
|
+
|
32
|
+
it { subject.get('/hello/world/rest').status.should == 200 }
|
33
|
+
it { subject.get('/hello/world/rest').body.should == '/rest world' }
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Rendering::File do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.base_application Mojito::Rendering::File do
|
11
|
+
file! __FILE__
|
12
|
+
end.mock_request
|
13
|
+
end
|
14
|
+
|
15
|
+
it { subject.get('/').status.should == 200 }
|
16
|
+
it { subject.get('/').headers.should include('Content-Type') }
|
17
|
+
it { subject.get('/').headers['Content-Type'].should == 'application/x-ruby' }
|
18
|
+
it { subject.get('/').headers.should include('Content-Length') }
|
19
|
+
it { subject.get('/').headers['Content-Length'].should == ::File.size(__FILE__).to_s }
|
20
|
+
it { subject.get('/').headers.should include('Last-Modified') }
|
21
|
+
it { subject.get('/').headers['Last-Modified'].should == ::File.mtime(__FILE__).rfc2822 }
|
22
|
+
it { subject.get('/').body.should == ::File.read(__FILE__) }
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Rendering::StatusCodes do
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Mojito.base_application Mojito::Matchers::Path, Mojito::Rendering::StatusCodes do
|
11
|
+
on 'ok' do ok! end
|
12
|
+
on 'not_found' do not_found! end
|
13
|
+
on 'internal_server_error' do internal_server_error! end
|
14
|
+
on 'unavailable' do unavailable! end
|
15
|
+
on 'redirect' do redirect! '/test' end
|
16
|
+
end.mock_request
|
17
|
+
end
|
18
|
+
|
19
|
+
it { subject.get('/ok').status.should == 200 }
|
20
|
+
it { subject.get('/not_found').status.should == 404 }
|
21
|
+
it { subject.get('/internal_server_error').status.should == 500 }
|
22
|
+
it { subject.get('/unavailable').status.should == 503 }
|
23
|
+
it { subject.get('/redirect').status.should == 302 }
|
24
|
+
it { subject.get('/redirect').headers['Location'].should == '/test' }
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'simplecov' and SimpleCov.start do
|
3
|
+
add_filter "spec/"
|
4
|
+
end
|
5
|
+
require 'mojito'
|
6
|
+
|
7
|
+
describe Mojito::Rendering::Templates do
|
8
|
+
|
9
|
+
context 'inline templates' do
|
10
|
+
subject do
|
11
|
+
Mojito.base_application Mojito::Rendering::Templates do
|
12
|
+
template :erb, 'before <%= var %> <%= yield %> after', :var => 'middle' do 'inside the block' end
|
13
|
+
halt!
|
14
|
+
end.mock_request
|
15
|
+
end
|
16
|
+
|
17
|
+
it { subject.get('/').status.should == 200 }
|
18
|
+
it { subject.get('/').body.should == 'before middle inside the block after' }
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'file templates' do
|
23
|
+
subject do
|
24
|
+
Mojito.base_application Mojito::Rendering::Templates do
|
25
|
+
template 'test.html.erb', :var => 'middle' do 'inside the block' end
|
26
|
+
halt!
|
27
|
+
end.mock_request
|
28
|
+
end
|
29
|
+
|
30
|
+
it { subject.get('/').status.should == 200 }
|
31
|
+
it { subject.get('/').body.should == 'HTML file with a variable middle and a yield inside the block' }
|
32
|
+
it { subject.get('/').headers.should include('Content-Type') }
|
33
|
+
it { subject.get('/').headers['Content-Type'].should == 'text/html' }
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -3,87 +3,3 @@ require 'simplecov' and SimpleCov.start do
|
|
3
3
|
add_filter "spec/"
|
4
4
|
end
|
5
5
|
require 'mojito'
|
6
|
-
|
7
|
-
describe Mojito::Rendering::Content do
|
8
|
-
|
9
|
-
subject do
|
10
|
-
Mojito.base_application Mojito::Rendering::Content do
|
11
|
-
on do write 'test content' ; halt! end
|
12
|
-
end.mock_request
|
13
|
-
end
|
14
|
-
|
15
|
-
it { subject.get('/').body.should == 'test content' }
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Mojito::Rendering::StatusCodes do
|
20
|
-
|
21
|
-
subject do
|
22
|
-
Mojito.base_application Mojito::Matchers::Path, Mojito::Rendering::StatusCodes do
|
23
|
-
on 'ok' do ok! end
|
24
|
-
on 'not_found' do not_found! end
|
25
|
-
on 'internal_server_error' do internal_server_error! end
|
26
|
-
on 'unavailable' do unavailable! end
|
27
|
-
on 'redirect' do redirect! '/test' end
|
28
|
-
end.mock_request
|
29
|
-
end
|
30
|
-
|
31
|
-
it { subject.get('/ok').status.should == 200 }
|
32
|
-
it { subject.get('/not_found').status.should == 404 }
|
33
|
-
it { subject.get('/internal_server_error').status.should == 500 }
|
34
|
-
it { subject.get('/unavailable').status.should == 503 }
|
35
|
-
it { subject.get('/redirect').status.should == 302 }
|
36
|
-
it { subject.get('/redirect').headers['Location'].should == '/test' }
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
describe Mojito::Rendering::Delegation do
|
41
|
-
|
42
|
-
subject do
|
43
|
-
sub_app = Mojito.base_application Mojito::R::Content, Mojito::R::Delegation do
|
44
|
-
on true do write 'sub-application' ; halt! end
|
45
|
-
end
|
46
|
-
Mojito.base_application Mojito::Rendering::Content, Mojito::Rendering::Delegation do
|
47
|
-
on true do run! sub_app end
|
48
|
-
end.mock_request
|
49
|
-
end
|
50
|
-
|
51
|
-
it { subject.get('/').status.should == 200 }
|
52
|
-
it { subject.get('/').body.should == 'sub-application' }
|
53
|
-
|
54
|
-
context do
|
55
|
-
|
56
|
-
subject do
|
57
|
-
sub_app = Mojito.base_application Mojito::R::Content, Mojito::R::Delegation, Mojito::H::Shortcuts do
|
58
|
-
on true do write("#{path_info} #{captures.first}") ; halt! end
|
59
|
-
end
|
60
|
-
Mojito.base_application Mojito::M::Path, Mojito::R::Content, Mojito::R::Delegation do
|
61
|
-
on PATH('hello/:name') do run! sub_app end
|
62
|
-
end.mock_request
|
63
|
-
end
|
64
|
-
|
65
|
-
it { subject.get('/hello/world/rest').status.should == 200 }
|
66
|
-
it { subject.get('/hello/world/rest').body.should == '/rest world' }
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
describe Mojito::Rendering::File do
|
73
|
-
|
74
|
-
subject do
|
75
|
-
Mojito.base_application Mojito::Rendering::File do
|
76
|
-
file! __FILE__
|
77
|
-
end.mock_request
|
78
|
-
end
|
79
|
-
|
80
|
-
it { subject.get('/').status.should == 200 }
|
81
|
-
it { subject.get('/').headers.should include('Content-Type') }
|
82
|
-
it { subject.get('/').headers['Content-Type'].should == 'application/x-ruby' }
|
83
|
-
it { subject.get('/').headers.should include('Content-Length') }
|
84
|
-
it { subject.get('/').headers['Content-Length'].should == ::File.size(__FILE__).to_s }
|
85
|
-
it { subject.get('/').headers.should include('Last-Modified') }
|
86
|
-
it { subject.get('/').headers['Last-Modified'].should == ::File.mtime(__FILE__).rfc2822 }
|
87
|
-
it { subject.get('/').body.should == ::File.read(__FILE__) }
|
88
|
-
|
89
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &19113520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19113520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mime-types
|
27
|
-
requirement: &
|
27
|
+
requirement: &19113040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.18'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19113040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tilt
|
38
|
-
requirement: &
|
38
|
+
requirement: &19112500 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.3.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19112500
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: extlib
|
49
|
-
requirement: &
|
49
|
+
requirement: &19111980 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,21 @@ dependencies:
|
|
54
54
|
version: 0.9.15
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *19111980
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: where-am-i
|
60
|
+
requirement: &19111420 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *19111420
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rspec
|
60
|
-
requirement: &
|
71
|
+
requirement: &19110940 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 2.8.0
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *19110940
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: rdoc
|
71
|
-
requirement: &
|
82
|
+
requirement: &19110400 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ~>
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '3.12'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *19110400
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: bundler
|
82
|
-
requirement: &
|
93
|
+
requirement: &19109880 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ~>
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: 1.0.0
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *19109880
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: jeweler
|
93
|
-
requirement: &
|
104
|
+
requirement: &19208400 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ~>
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: 1.8.3
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *19208400
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: rcov
|
104
|
-
requirement: &
|
115
|
+
requirement: &19207820 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,7 +120,7 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *19207820
|
113
124
|
description: A simple yet powerful webframework largely inspired by Rum and Cuba
|
114
125
|
email: dev@trense.info
|
115
126
|
executables: []
|
@@ -126,8 +137,11 @@ files:
|
|
126
137
|
- lib/mojito/helpers/exception_handling.rb
|
127
138
|
- lib/mojito/helpers/shortcuts.rb
|
128
139
|
- lib/mojito/matchers.rb
|
140
|
+
- lib/mojito/matchers/environment.rb
|
129
141
|
- lib/mojito/matchers/methods.rb
|
130
142
|
- lib/mojito/matchers/path.rb
|
143
|
+
- lib/mojito/matchers/session.rb
|
144
|
+
- lib/mojito/matchers/url_scheme.rb
|
131
145
|
- lib/mojito/matchers/virtual_host.rb
|
132
146
|
- lib/mojito/rendering.rb
|
133
147
|
- lib/mojito/rendering/content.rb
|
@@ -135,10 +149,21 @@ files:
|
|
135
149
|
- lib/mojito/rendering/delegation.rb
|
136
150
|
- lib/mojito/rendering/file.rb
|
137
151
|
- lib/mojito/rendering/status_codes.rb
|
152
|
+
- lib/mojito/rendering/templates.rb
|
138
153
|
- lib/mojito/request_extensions.rb
|
139
154
|
- lib/mojito/utils/status_codes.rb
|
140
155
|
- spec/mojito/helpers_spec.rb
|
156
|
+
- spec/mojito/matchers/methods_spec.rb
|
157
|
+
- spec/mojito/matchers/path_spec.rb
|
158
|
+
- spec/mojito/matchers/session_spec.rb
|
159
|
+
- spec/mojito/matchers/url_scheme_spec.rb
|
160
|
+
- spec/mojito/matchers/virtual_host_spec.rb
|
141
161
|
- spec/mojito/matchers_spec.rb
|
162
|
+
- spec/mojito/rendering/content_spec.rb
|
163
|
+
- spec/mojito/rendering/delegation_spec.rb
|
164
|
+
- spec/mojito/rendering/file_spec.rb
|
165
|
+
- spec/mojito/rendering/status_codes_spec.rb
|
166
|
+
- spec/mojito/rendering/templates_spec.rb
|
142
167
|
- spec/mojito/rendering_spec.rb
|
143
168
|
- spec/mojito/request_extensions_spec.rb
|
144
169
|
- spec/mojito_spec.rb
|