forked from sinatra/sinatra
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroute_added_hook_test.rb
59 lines (48 loc) · 1.33 KB
/
route_added_hook_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require File.expand_path('../helper', __FILE__)
module RouteAddedTest
@routes, @procs = [], []
def self.routes ; @routes ; end
def self.procs ; @procs ; end
def self.route_added(verb, path, proc)
@routes << [verb, path]
@procs << proc
end
end
class RouteAddedHookTest < Test::Unit::TestCase
setup {
RouteAddedTest.routes.clear
RouteAddedTest.procs.clear
}
it "should be notified of an added route" do
mock_app(Class.new(Sinatra::Base)) {
register RouteAddedTest
get('/') {}
}
assert_equal [["GET", "/"], ["HEAD", "/"]],
RouteAddedTest.routes
end
it "should include hooks from superclass" do
a = Class.new(Class.new(Sinatra::Base))
b = Class.new(a)
a.register RouteAddedTest
b.class_eval { post("/sub_app_route") {} }
assert_equal [["POST", "/sub_app_route"]],
RouteAddedTest.routes
end
it "should only run once per extension" do
mock_app(Class.new(Sinatra::Base)) {
register RouteAddedTest
register RouteAddedTest
get('/') {}
}
assert_equal [["GET", "/"], ["HEAD", "/"]],
RouteAddedTest.routes
end
it "should pass route blocks as an argument" do
mock_app(Class.new(Sinatra::Base)) {
register RouteAddedTest
get('/') {}
}
assert_kind_of Proc, RouteAddedTest.procs.first
end
end