Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (48 sloc) 1.352 kb
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
1 require File.dirname(__FILE__) + '/helper'
2
3 module RouteAddedTest
d6ceeb0 @tj Added proc as argument for #route_added hook
tj authored
4 @routes, @procs = [], []
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
5 def self.routes ; @routes ; end
d6ceeb0 @tj Added proc as argument for #route_added hook
tj authored
6 def self.procs ; @procs ; end
7 def self.route_added(verb, path, proc)
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
8 @routes << [verb, path]
d6ceeb0 @tj Added proc as argument for #route_added hook
tj authored
9 @procs << proc
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
10 end
11 end
12
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
13 class RouteAddedHookTest < Test::Unit::TestCase
d6ceeb0 @tj Added proc as argument for #route_added hook
tj authored
14 setup {
15 RouteAddedTest.routes.clear
16 RouteAddedTest.procs.clear
17 }
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
18
19 it "should be notified of an added route" do
20 mock_app(Class.new(Sinatra::Base)) {
21 register RouteAddedTest
22 get('/') {}
23 }
24
25 assert_equal [["GET", "/"], ["HEAD", "/"]],
26 RouteAddedTest.routes
27 end
28
29 it "should include hooks from superclass" do
30 a = Class.new(Class.new(Sinatra::Base))
31 b = Class.new(a)
32
33 a.register RouteAddedTest
34 b.class_eval { post("/sub_app_route") {} }
35
36 assert_equal [["POST", "/sub_app_route"]],
37 RouteAddedTest.routes
38 end
39
40 it "should only run once per extension" do
41 mock_app(Class.new(Sinatra::Base)) {
42 register RouteAddedTest
43 register RouteAddedTest
44 get('/') {}
45 }
46
47 assert_equal [["GET", "/"], ["HEAD", "/"]],
48 RouteAddedTest.routes
49 end
d6ceeb0 @tj Added proc as argument for #route_added hook
tj authored
50
51 it "should pass route blocks as an argument" do
52 mock_app(Class.new(Sinatra::Base)) {
53 register RouteAddedTest
54 get('/') {}
55 }
56
57 assert_kind_of Proc, RouteAddedTest.procs.first
58 end
8b8ddfe @bmizerany Hook mechanizm for route_added [help from rtomayko]
bmizerany authored
59 end
Something went wrong with that request. Please try again.