lotus-router 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/routing_test.rb DELETED
@@ -1,99 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Lotus::Router do
4
- before do
5
- @router = Lotus::Router.new
6
- @app = Rack::MockRequest.new(@router)
7
- end
8
-
9
- after do
10
- @router.reset!
11
- end
12
-
13
- def endpoint(response)
14
- ->(env) { response }
15
- end
16
-
17
- [ 'get', 'post', 'delete', 'put', 'patch', 'trace', 'options' ].each do |verb|
18
-
19
- describe "##{ verb }" do
20
- describe 'path recognition' do
21
- it 'recognize fixed string' do
22
- response = [200, {}, ['Fixed!']]
23
- @router.send(verb, '/lotus', to: endpoint(response))
24
-
25
- response.must_be_same_as @app.request(verb.upcase, '/lotus')
26
- end
27
-
28
- it 'recognize moving parts string' do
29
- response = [200, {}, ['Moving!']]
30
- @router.send(verb, '/lotus/:id', to: endpoint(response))
31
-
32
- response.must_be_same_as @app.request(verb.upcase, '/lotus/23')
33
- end
34
-
35
- it 'recognize globbing string' do
36
- response = [200, {}, ['Globbing!']]
37
- @router.send(verb, '/lotus/*', to: endpoint(response))
38
-
39
- response.must_be_same_as @app.request(verb.upcase, '/lotus/all')
40
- end
41
-
42
- it 'recognize format string' do
43
- response = [200, {}, ['Format!']]
44
- @router.send(verb, '/lotus/:id(.:format)', to: endpoint(response))
45
-
46
- response.must_be_same_as @app.request(verb.upcase, '/lotus/all.json')
47
- end
48
-
49
- it 'accepts a block' do
50
- response = [200, {}, ['Block!']]
51
- @router.send(verb, '/block') {|e| response }
52
-
53
- response.must_be_same_as @app.request(verb.upcase, '/block')
54
- end
55
- end
56
-
57
- describe 'named routes' do
58
- it 'recognizes by the given symbol' do
59
- response = [200, {}, ['Named route!']]
60
-
61
- @router.send(verb, '/named_route', to: endpoint(response), as: :"#{ verb }_named_route")
62
-
63
- @router.path(:"#{ verb }_named_route").must_equal '/named_route'
64
- @router.url(:"#{ verb }_named_route").must_equal 'http://localhost/named_route'
65
- end
66
-
67
- it 'compiles variables' do
68
- response = [200, {}, ['Named %route!']]
69
-
70
- @router.send(verb, '/named_:var', to: endpoint(response), as: :"#{ verb }_named_route_var")
71
-
72
- @router.path(:"#{ verb }_named_route_var", var: 'route').must_equal '/named_route'
73
- @router.url(:"#{ verb }_named_route_var", var: 'route').must_equal 'http://localhost/named_route'
74
- end
75
-
76
- it 'allows custom url parts' do
77
- response = [200, {}, ['Named route with custom parts!']]
78
-
79
- router = Lotus::Router.new(scheme: 'https', host: 'lotusrb.org', port: 443)
80
- router.send(verb, '/custom_named_route', to: endpoint(response), as: :"#{ verb }_custom_named_route")
81
-
82
- router.url(:"#{ verb }_custom_named_route").must_equal 'https://lotusrb.org/custom_named_route'
83
- end
84
- end
85
-
86
- describe 'constraints' do
87
- it 'recognize when called with matching constraints' do
88
- response = [200, {}, ['Moving with constraints!']]
89
-
90
- @router.send(verb, '/lotus/:id', to: endpoint(response), id: /\d+/)
91
- response.must_be_same_as @app.request(verb.upcase, '/lotus/23')
92
-
93
- @app.request(verb.upcase, '/lotus/flower').status.must_equal 404
94
- end
95
- end
96
-
97
- end # main each
98
- end
99
- end
data/test/test_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- if ENV['COVERAGE']
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter 'test'
5
- command_name 'Mintest'
6
- end
7
- end
8
-
9
- require 'rubygems'
10
- require 'bundler/setup'
11
- require 'coveralls'
12
- Coveralls.wear!
13
- require 'minitest/autorun'
14
- require 'fixtures'
15
- $:.unshift 'lib'
16
- require 'lotus-router'
17
-
18
- Rack::MockResponse.class_eval do
19
- def equal?(other)
20
- other = Rack::MockResponse.new(*other)
21
-
22
- status == other.status &&
23
- headers == other.headers &&
24
- body == other.body
25
- end
26
- end
27
-
28
- Lotus::Router.class_eval do
29
- def reset!
30
- @router.reset!
31
- end
32
- end
data/test/version_test.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe Lotus::Router::VERSION do
4
- it 'exposes version' do
5
- Lotus::Router::VERSION.must_equal '0.1.0'
6
- end
7
- end