http_router 0.4.1 → 0.5.0

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.
Files changed (42) hide show
  1. data/Rakefile +6 -5
  2. data/benchmarks/rack_mount.rb +16 -45
  3. data/benchmarks/rec2.rb +8 -8
  4. data/http_router.gemspec +5 -4
  5. data/lib/http_router/interface/sinatra.rb +7 -7
  6. data/lib/http_router/node.rb +106 -105
  7. data/lib/http_router/optional_compiler.rb +14 -5
  8. data/lib/http_router/path.rb +18 -28
  9. data/lib/http_router/root.rb +17 -29
  10. data/lib/http_router/route.rb +47 -16
  11. data/lib/http_router/static.rb +5 -0
  12. data/lib/http_router/variable.rb +2 -5
  13. data/lib/http_router/version.rb +1 -1
  14. data/lib/http_router.rb +38 -65
  15. data/test/helper.rb +74 -0
  16. data/test/rack/test_dispatch.rb +120 -0
  17. data/test/rack/test_route.rb +44 -0
  18. data/test/rack/test_urlmap.rb +12 -0
  19. data/{spec → test}/sinatra/recognize_spec.rb +0 -0
  20. data/test/sinatra/test_recognize.rb +150 -0
  21. data/test/test_arbitrary.rb +50 -0
  22. data/test/test_generate.rb +93 -0
  23. data/test/test_greedy.rb +24 -0
  24. data/test/test_interstitial.rb +47 -0
  25. data/test/test_misc.rb +30 -0
  26. data/test/test_mounting.rb +89 -0
  27. data/test/test_recognize.rb +56 -0
  28. data/test/test_request.rb +85 -0
  29. data/test/test_trailing_slash.rb +28 -0
  30. data/test/test_variable.rb +108 -0
  31. metadata +41 -32
  32. data/lib/http_router/response.rb +0 -46
  33. data/spec/generate_spec.rb +0 -234
  34. data/spec/misc_spec.rb +0 -65
  35. data/spec/mounting_spec.rb +0 -5
  36. data/spec/rack/dispatch_spec.rb +0 -119
  37. data/spec/rack/generate_spec.rb +0 -29
  38. data/spec/rack/middleware_spec.rb +0 -22
  39. data/spec/rack/route_spec.rb +0 -72
  40. data/spec/rack/urlmap_spec.rb +0 -13
  41. data/spec/recognize_spec.rb +0 -497
  42. data/spec/spec_helper.rb +0 -25
@@ -0,0 +1,108 @@
1
+ class TestVariable < MiniTest::Unit::TestCase
2
+ def test_variable
3
+ assert_route ':one', '/two', {:one => 'two'}
4
+ assert_route 'test/:one', '/test/three', {:one => 'three'}
5
+ end
6
+
7
+ def test_variable_vs_static
8
+ dynamic, static = router { add ':one'; add 'one' }
9
+ assert_route dynamic, '/two', {:one => 'two'}
10
+ assert_route static, '/one'
11
+ end
12
+
13
+ def test_variable_with_static_after
14
+ variable, static = router {
15
+ add '/:var/one'
16
+ add 'one'
17
+ }
18
+ assert_route variable, '/two/one', {:var => 'two'}
19
+ assert_route static, '/one'
20
+ assert_route nil, '/two'
21
+ end
22
+
23
+ def test_variable_and_static
24
+ dynamic, static = router {
25
+ add("/foo/:id")
26
+ add("/foo")
27
+ }
28
+ assert_route dynamic, '/foo/id', {:id => 'id'}
29
+ assert_route static, '/foo'
30
+ end
31
+
32
+ def test_anonymous_variable
33
+ assert_route '/foo/:', '/foo/id', {:'$1' => 'id'}
34
+ assert_route 'foo/:/:', '/foo/id/what', {:'$1' => 'id', :'$2' => 'what'}
35
+ assert_route 'foo/*/test', '/foo/id1/id2/test', {:'$1' => ['id1', 'id2']}
36
+ assert_route '/foo/*/what/:', '/foo/id1/id2/what/more', {:'$1' => ['id1', 'id2'], :'$2' => 'more'}
37
+ end
38
+
39
+ def test_variable_mixed_with_static
40
+ static, dynamic = router {
41
+ add("/foo/foo")
42
+ add("/:foo/foo2")
43
+ }
44
+ assert_route dynamic, '/foo/foo2', {:foo => 'foo'}
45
+ assert_route static, '/foo/foo'
46
+ end
47
+
48
+ def test_encoding
49
+ assert_route '/:var', '/%E6%AE%BA%E3%81%99', {:var => "\346\256\272\343\201\231"}
50
+ end
51
+
52
+ def test_match_path
53
+ r = router { add('/:test').match_path(%r{/(test123|\d+)}) }
54
+ assert_route r, '/test123', {:test => "test123"}
55
+ assert_route r, '/123', {:test => "123"}
56
+ assert_route nil, '/test123andmore'
57
+ assert_route nil, '/lesstest123'
58
+ end
59
+
60
+ def test_format
61
+ assert_route '/test.:format', '/test.html', {:format => 'html'}
62
+ end
63
+
64
+ def test_optional_format
65
+ r = router {add('/test(.:format)')}
66
+ assert_route r, '/test.html', {:format => 'html'}
67
+ assert_route r, '/test'
68
+ end
69
+
70
+ def test_bare_optional_format
71
+ r = router {add('(.:format)')}
72
+ assert_route r, '/.html', {:format => 'html'}
73
+ assert_route r, '/'
74
+ end
75
+
76
+ def test_var_with_format
77
+ assert_route '/:test.:format', '/foo.bar', {:test => 'foo', :format => 'bar'}
78
+ end
79
+
80
+ def test_var_with_optional_format
81
+ r = router { add('/:test(.:format)') }
82
+ assert_route r, '/foo.bar', {:test => 'foo', :format => 'bar'}
83
+ assert_route r, '/foo', {:test => 'foo'}
84
+ end
85
+
86
+ def test_glob
87
+ assert_route '/test/*variable', 'test/one/two/three', {:variable => ['one', 'two', 'three']}
88
+ end
89
+
90
+ def test_glob_with_static
91
+ assert_route '/test/*variable/test', '/test/one/two/three/test', {:variable => ['one', 'two', 'three']}
92
+ end
93
+
94
+ def test_glob_with_regex
95
+ r = router { add('/test/*variable/anymore')}
96
+ assert_route r, '/test/123/345/567/anymore', {:variable => ['123', '345', '567']}
97
+ assert_route nil, '/test/123/345/567'
98
+ end
99
+
100
+ def test_regex_and_greedy
101
+ with_regex, without_regex = router {
102
+ add("/:common_variable/:matched").matching(:matched => /\d+/)
103
+ add("/:common_variable/:unmatched")
104
+ }
105
+ assert_route with_regex, '/common/123', {:common_variable => 'common', :matched => '123'}
106
+ assert_route without_regex, '/common/other', {:common_variable => 'common', :unmatched => 'other'}
107
+ end
108
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-18 00:00:00 -07:00
18
+ date: 2010-12-06 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ dependencies:
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: rspec
54
+ name: minitest
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
57
  none: false
@@ -123,9 +123,23 @@ dependencies:
123
123
  type: :development
124
124
  version_requirements: *id007
125
125
  - !ruby/object:Gem::Dependency
126
- name: bundler
126
+ name: phocus
127
127
  prerelease: false
128
128
  requirement: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ type: :development
138
+ version_requirements: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ name: bundler
141
+ prerelease: false
142
+ requirement: &id009 !ruby/object:Gem::Requirement
129
143
  none: false
130
144
  requirements:
131
145
  - - ~>
@@ -137,7 +151,7 @@ dependencies:
137
151
  - 0
138
152
  version: 1.0.0
139
153
  type: :development
140
- version_requirements: *id008
154
+ version_requirements: *id009
141
155
  description: This library allows you to recognize and build URLs in a Rack application. As well it contains an interface for use within Sinatra.
142
156
  email: joshbuddy@gmail.com
143
157
  executables: []
@@ -182,22 +196,27 @@ files:
182
196
  - lib/http_router/rack.rb
183
197
  - lib/http_router/rack/builder.rb
184
198
  - lib/http_router/rack/url_map.rb
185
- - lib/http_router/response.rb
186
199
  - lib/http_router/root.rb
187
200
  - lib/http_router/route.rb
201
+ - lib/http_router/static.rb
188
202
  - lib/http_router/variable.rb
189
203
  - lib/http_router/version.rb
190
- - spec/generate_spec.rb
191
- - spec/misc_spec.rb
192
- - spec/mounting_spec.rb
193
- - spec/rack/dispatch_spec.rb
194
- - spec/rack/generate_spec.rb
195
- - spec/rack/middleware_spec.rb
196
- - spec/rack/route_spec.rb
197
- - spec/rack/urlmap_spec.rb
198
- - spec/recognize_spec.rb
199
- - spec/sinatra/recognize_spec.rb
200
- - spec/spec_helper.rb
204
+ - test/helper.rb
205
+ - test/rack/test_dispatch.rb
206
+ - test/rack/test_route.rb
207
+ - test/rack/test_urlmap.rb
208
+ - test/sinatra/recognize_spec.rb
209
+ - test/sinatra/test_recognize.rb
210
+ - test/test_arbitrary.rb
211
+ - test/test_generate.rb
212
+ - test/test_greedy.rb
213
+ - test/test_interstitial.rb
214
+ - test/test_misc.rb
215
+ - test/test_mounting.rb
216
+ - test/test_recognize.rb
217
+ - test/test_request.rb
218
+ - test/test_trailing_slash.rb
219
+ - test/test_variable.rb
201
220
  has_rdoc: true
202
221
  homepage: http://github.com/joshbuddy/http_router
203
222
  licenses: []
@@ -232,15 +251,5 @@ rubygems_version: 1.3.7
232
251
  signing_key:
233
252
  specification_version: 3
234
253
  summary: A kick-ass HTTP router for use in Rack & Sinatra
235
- test_files:
236
- - spec/generate_spec.rb
237
- - spec/misc_spec.rb
238
- - spec/mounting_spec.rb
239
- - spec/rack/dispatch_spec.rb
240
- - spec/rack/generate_spec.rb
241
- - spec/rack/middleware_spec.rb
242
- - spec/rack/route_spec.rb
243
- - spec/rack/urlmap_spec.rb
244
- - spec/recognize_spec.rb
245
- - spec/sinatra/recognize_spec.rb
246
- - spec/spec_helper.rb
254
+ test_files: []
255
+
@@ -1,46 +0,0 @@
1
- class HttpRouter
2
- module Response
3
- def self.matched(*args)
4
- Matched.new(*args)
5
- end
6
-
7
- def self.unmatched(*args)
8
- Unmatched.new(*args)
9
- end
10
-
11
- private
12
- class Unmatched < Struct.new(:status, :headers)
13
- def matched?
14
- false
15
- end
16
- end
17
-
18
- class Matched < Struct.new(:path, :params, :matched_path, :remaining_path)
19
- attr_reader :params_as_hash, :route
20
-
21
- def initialize(path, params, matched_path, remaining_path = nil)
22
- raise if matched_path.nil?
23
- super
24
- path.splitting_indexes and path.splitting_indexes.each{|i| params[i] = params[i].split(HttpRouter::Parts::SLASH_RX)}
25
- @params_as_hash = path.hashify_params(params)
26
- end
27
-
28
- def matched?
29
- true
30
- end
31
-
32
- def route
33
- path.route
34
- end
35
-
36
- def dest
37
- route.dest
38
- end
39
- alias_method :destination, :dest
40
-
41
- def partial_match?
42
- route.partially_match?
43
- end
44
- end
45
- end
46
- end
@@ -1,234 +0,0 @@
1
- require 'spec_helper'
2
- describe "HttpRouter#generate" do
3
- before(:each) do
4
- @router = HttpRouter.new
5
- end
6
-
7
- context("static paths") do
8
- ['/', '/test', '/test/time', '/one/more/what', '/test.html'].each do |path|
9
- it "should generate #{path.inspect}" do
10
- route = @router.add(path).compile
11
- @router.url(route).should == path
12
- end
13
- end
14
- end
15
-
16
- context("dynamic paths") do
17
- it "should generate from a hash" do
18
- @router.add("/:var").name(:test).compile
19
- @router.url(:test, :var => 'test').should == '/test'
20
- end
21
-
22
- it "should generate from a hash with extra parts going to the query string" do
23
- @router.add("/:var").name(:test).compile
24
- @router.url(:test, :var => 'test', :query => 'string').should == '/test?query=string'
25
- end
26
-
27
- it "should generate from an array" do
28
- @router.add("/:var").name(:test).compile
29
- @router.url(:test, 'test').should == '/test'
30
- end
31
-
32
- it "should generate from an array with extra parts going to the query string" do
33
- @router.add("/:var").name(:test).compile
34
- @router.url(:test, 'test', :query => 'string').should == '/test?query=string'
35
- end
36
-
37
- it "should generate with multiple dynamics" do
38
- @router.add("/:var/:baz").name(:test).compile
39
- @router.url(:test, 'one', 'two').should == '/one/two'
40
- @router.url(:test, :var => 'one', :baz => 'two').should == '/one/two'
41
- end
42
-
43
- context "with a :format" do
44
- it "should generate with a format" do
45
- @router.add("/test.:format").name(:test).compile
46
- @router.url(:test, 'html').should == '/test.html'
47
- end
48
-
49
- it "should generate with a format as a hash" do
50
- @router.add("/test.:format").name(:test).compile
51
- @router.url(:test, :format => 'html').should == '/test.html'
52
- end
53
-
54
- it "should generate with format as a symbol" do
55
- @router.add("/test.:format").name(:test).compile
56
- @router.url(:test, :format => :html).should == '/test.html'
57
- end
58
-
59
- it "should generate with an optional format" do
60
- @router.add("/test(.:format)").name(:test).compile
61
- @router.url(:test, 'html').should == '/test.html'
62
- @router.url(:test).should == '/test'
63
- end
64
-
65
- it "should generate a dynamic path and a format" do
66
- @router.add("/:var1.:format").name(:test).compile
67
- @router.url(:test, 'var', :format => 'html').should == '/var.html'
68
- end
69
-
70
- it "should generate a dynamic path and an optional format" do
71
- @router.add("/:var1(.:format)").name(:test).compile
72
- @router.url(:test, 'var').should == '/var'
73
- @router.url(:test, 'var', :format => 'html').should == '/var.html'
74
- end
75
-
76
- it "should generate multiple dynamics and a format" do
77
- @router.add("/:foo/:bar.:format").name(:test).compile
78
- @router.url(:test, 'var', 'baz', 'html').should == '/var/baz.html'
79
- @router.url(:test, :foo => 'var', :bar => 'baz', :format => 'html').should == '/var/baz.html'
80
- end
81
-
82
- it "should generate multiple dynamics and an optional format" do
83
- @router.add("/:foo/:bar(.:format)").name(:test).compile
84
- @router.url(:test, 'var', 'baz').should == '/var/baz'
85
- @router.url(:test, 'var', 'baz', 'html').should == '/var/baz.html'
86
- @router.url(:test, :foo => 'var', :bar => 'baz').should == '/var/baz'
87
- @router.url(:test, :foo => 'var', :bar => 'baz', :format => 'html').should == '/var/baz.html'
88
- end
89
- end
90
-
91
- context "with optional parts" do
92
- it "should generate both" do
93
- @router.add("/:var1(/:var2)").name(:test).compile
94
- @router.url(:test, 'var').should == '/var'
95
- @router.url(:test, 'var', 'fooz').should == '/var/fooz'
96
- @router.url(:test, :var1 => 'var').should == '/var'
97
- @router.url(:test, :var1 => 'var', :var2 => 'fooz').should == '/var/fooz'
98
- proc{@router.url(:test, :var2 => 'fooz').should == '/var/fooz'}.should raise_error(HttpRouter::UngeneratableRouteException)
99
- end
100
- it "should generate with a format" do
101
- @router.add("/:var1(/:var2.:format)").name(:test).compile
102
- @router.url(:test, 'var').should == '/var'
103
- @router.url(:test, 'var', 'fooz', 'html').should == '/var/fooz.html'
104
- @router.url(:test, :var1 => 'var').should == '/var'
105
- @router.url(:test, :var1 => 'var', :var2 => 'fooz', :format => 'html').should == '/var/fooz.html'
106
- end
107
- it "should generate with an embeded optional" do
108
- @router.add("/:var1(/:var2(/:var3))").name(:test).compile
109
- @router.url(:test, 'var').should == '/var'
110
- @router.url(:test, 'var', 'fooz').should == '/var/fooz'
111
- @router.url(:test, 'var', 'fooz', 'baz').should == '/var/fooz/baz'
112
- @router.url(:test, :var1 => 'var').should == '/var'
113
- @router.url(:test, :var1 => 'var', :var2 => 'fooz', :var3 => 'baz').should == '/var/fooz/baz'
114
- end
115
-
116
- it "should support optional plus optional format" do
117
- @router.add("/:var1(/:var2)(.:format)").name(:test).compile
118
- @router.url(:test, 'var').should == '/var'
119
- @router.url(:test, 'var', 'fooz').should == '/var/fooz'
120
- @router.url(:test, 'var', 'fooz', 'html').should == '/var/fooz.html'
121
- @router.url(:test, :var1 => 'var').should == '/var'
122
- @router.url(:test, :var1 => 'var', :var2 => 'fooz', :format => 'html').should == '/var/fooz.html'
123
- @router.url(:test, :var1 => 'var', :format => 'html').should == '/var.html'
124
- end
125
- end
126
-
127
- context "with default values" do
128
- it "should generate with all params" do
129
- @router.add("/:var").default(:page => 1).name(:test).compile
130
- @router.url(:test, 123).should == "/123?page=1"
131
- end
132
- end
133
-
134
- context "with nil values" do
135
- it "shouldn't use nil values" do
136
- @router.add("/url(/:var)").name(:test).compile
137
- @router.url(:test, :var => nil).should == "/url"
138
- end
139
- end
140
-
141
- context "with a matching" do
142
- it "should raise an exception when the route is invalid" do
143
- @router.add("/:var").matching(:var => /\d+/).name(:test).compile
144
- proc{@router.url(:test, 'asd')}.should raise_error(HttpRouter::InvalidRouteException)
145
- end
146
- end
147
-
148
- context "url mounting" do
149
- context "nested routes" do
150
- before(:each) do
151
- @r1 = HttpRouter.new
152
- @r2 = HttpRouter.new
153
- @r2.add("/bar").name(:test).compile
154
- end
155
-
156
- it "should set the url mount on a child route" do
157
- route = @r1.add("/foo").to(@r2)
158
- @r2.url_mount.url.should == "/foo"
159
- @r2.url(:test).should == "/foo/bar"
160
- end
161
-
162
- it "should set any default values on the url mount" do
163
- route = @r1.add("/foo/:bar").default(:bar => "baz").to(@r2)
164
- @r2.url(:test).should == "/foo/baz/bar"
165
- @r2.url(:test, :bar => "haha").should == "/foo/haha/bar"
166
- end
167
-
168
- it "should use multiple variables" do
169
- @r1.add("/foo/:bar/:baz").default(:bar => "bar").to(@r2)
170
- @r2.url(:test, :baz => "baz").should == "/foo/bar/baz/bar"
171
- end
172
-
173
- it "should not steal parameters from the defaults it doesn't need" do
174
- route = @r1.add("/foo/:bar").default(:bar => "baz").to(@r2)
175
- @r2.url(:test, :bang => "ers").should == "/foo/baz/bar?bang=ers"
176
- @r2.url(:test, :bar => "haha", :bang => "ers").should == "/foo/haha/bar?bang=ers"
177
- end
178
-
179
- it "should generate on a path with an optional variable" do
180
- @r1.add("/foo(/:bar)").to(@r2)
181
- @r2.add("/hey(/:there)").name(:test).compile
182
- @r2.url(:test).should == "/foo/hey"
183
- @r2.url(:test, :bar => "bar").should == "/foo/bar/hey"
184
- @r2.url(:test, :bar => "bar", :there => "there").should == "/foo/bar/hey/there"
185
- end
186
-
187
- it "should nest 3 times deeply" do
188
- @r3 = HttpRouter.new
189
- @r1.add("/foo(/:bar)").default(:bar => "barry").to(@r2)
190
- @r2.add("/hi").name(:hi).compile
191
- @r2.add("/mounted").to(@r3)
192
- @r3.add("/endpoint").name(:endpoint).compile
193
-
194
- @r2.url(:hi).should == "/foo/barry/hi"
195
- @r3.url(:endpoint).should == "/foo/barry/mounted/endpoint"
196
- @r3.url(:endpoint, :bar => "flower").should == "/foo/flower/mounted/endpoint"
197
- end
198
-
199
- it "should allow me to set the host via a default" do
200
- @r1.add("/mounted").default(:host => "example.com").to(@r2)
201
- @r2.url(:test).should == "http://example.com/mounted/bar"
202
- end
203
-
204
- it "should allow me to set the host via an option" do
205
- @r1.add("/mounted").to(@r2)
206
- @r2.url(:test).should == "/mounted/bar"
207
- @r2.url(:test, :host => "example.com").should == "http://example.com/mounted/bar"
208
- end
209
-
210
- it "should allow me to set the scheme via an option" do
211
- @r1.add("/mounted").to(@r2)
212
- @r2.url(:test).should == "/mounted/bar"
213
- @r2.url(:test, :scheme => "https", :host => "example.com").should == "https://example.com/mounted/bar"
214
- end
215
-
216
- it "should clone my nested structure" do
217
- @r3 = HttpRouter.new
218
- @r1.add("/first").to(@r2)
219
- @r2.add("/second").to(@r3)
220
- r1 = @r1.clone
221
- @r1.routes.first.should_not be_nil
222
- r2 = r1.routes.first.dest
223
- r2.should_not be_nil
224
- @r1.routes.first.dest.object_id.should == @r2.object_id
225
- r2.object_id.should_not == @r2.object_id
226
- r2.routes.should have(2).route
227
- r3 = r2.routes.last.dest
228
- r3.should be_an_instance_of(HttpRouter)
229
- r3.object_id.should_not == @r3.object_id
230
- end
231
- end
232
- end
233
- end
234
- end
data/spec/misc_spec.rb DELETED
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
- describe "HttpRouter" do
3
- before(:each) do
4
- @router = HttpRouter.new
5
- end
6
-
7
- context "route adding" do
8
- it "should work with options too" do
9
- route = @router.add('/:test', :conditions => {:request_method => %w{HEAD GET}, :host => 'host1'}, :default_values => {:page => 1}, :matching => {:test => /\d+/}, :name => :foobar).to :test
10
- @router.recognize(Rack::MockRequest.env_for('http://host2/variable', :method => 'POST')).should be_nil
11
- @router.recognize(Rack::MockRequest.env_for('http://host1/variable', :method => 'POST')).should be_nil
12
- @router.recognize(Rack::MockRequest.env_for('http://host2/123', :method => 'POST')).should be_nil
13
- @router.recognize(Rack::MockRequest.env_for('http://host1/123', :method => 'POST')).matched?.should be_false
14
- @router.recognize(Rack::MockRequest.env_for('http://host1/123', :method => 'GET' )).route.dest.should == :test
15
- @router.url(:foobar, '123').should == '/123?page=1'
16
- end
17
- end
18
-
19
- context "instance_eval block" do
20
- it "run the routes" do
21
- HttpRouter.new {
22
- add('/test').to :test
23
- }.recognize(Rack::MockRequest.env_for('/test', :method => 'GET')).dest.should == :test
24
- end
25
- end
26
-
27
- context "exceptions" do
28
- it "should be smart about multiple optionals" do
29
- proc {@router.add("/:var1(/:var2)(/:var3)").compile}.should raise_error(HttpRouter::AmbiguousRouteException)
30
- end
31
-
32
- it "should raise on identical variable name" do
33
- proc {@router.add("/:var1(/:var1)(/:var1)").compile}.should raise_error(HttpRouter::AmbiguousVariableException)
34
- end
35
-
36
- it "should raise on unsupported request methods" do
37
- proc {@router.add("/").condition(:flibberty => 'gibet').compile}.should raise_error(HttpRouter::UnsupportedRequestConditionError)
38
- end
39
- end
40
-
41
- context "cloning" do
42
- it "clone the routes" do
43
- r1 = HttpRouter.new {
44
- add('/test').name(:test_route).to :test
45
- }
46
- r2 = r1.clone
47
-
48
- r2.add('/test2').name(:test).to(:test2)
49
- r2.routes.size.should == 2
50
-
51
- r1.recognize(Rack::MockRequest.env_for('/test2')).should be_nil
52
- r2.recognize(Rack::MockRequest.env_for('/test2')).should_not be_nil
53
- r1.named_routes[:test_route].should == r1.routes.first
54
- r2.named_routes[:test_route].should == r2.routes.first
55
-
56
- r1.add('/another').name(:test).to(:test2)
57
-
58
- r1.routes.size.should == r2.routes.size
59
- r1.url(:test).should == '/another'
60
- r2.url(:test).should == '/test2'
61
- r1.routes.first.dest.should == :test
62
- r2.routes.first.dest.should == :test
63
- end
64
- end
65
- end
@@ -1,5 +0,0 @@
1
- describe "mounting" do
2
- before(:each) do
3
- @router = HttpRouter.new
4
- end
5
- end