mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
f10e571f4d
We use minitest for Sinatra's test suite but we weren't using its rake task. I've updated the Rakefile to require and use Minitest default rake task to simplify. Another change is to rename the `helper.rb` file to `test_helper.rb` because I think that name is used more in the community and require it directly without calling `File.expand_path`
59 lines
1.3 KiB
Ruby
59 lines
1.3 KiB
Ruby
require_relative 'test_helper'
|
|
|
|
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 < Minitest::Test
|
|
setup do
|
|
RouteAddedTest.routes.clear
|
|
RouteAddedTest.procs.clear
|
|
end
|
|
|
|
it "should be notified of an added route" do
|
|
mock_app(Class.new(Sinatra::Base)) do
|
|
register RouteAddedTest
|
|
get('/') {}
|
|
end
|
|
|
|
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)) do
|
|
register RouteAddedTest
|
|
register RouteAddedTest
|
|
get('/') {}
|
|
end
|
|
|
|
assert_equal [["GET", "/"], ["HEAD", "/"]],
|
|
RouteAddedTest.routes
|
|
end
|
|
|
|
it "should pass route blocks as an argument" do
|
|
mock_app(Class.new(Sinatra::Base)) do
|
|
register RouteAddedTest
|
|
get('/') {}
|
|
end
|
|
|
|
assert_kind_of Proc, RouteAddedTest.procs.first
|
|
end
|
|
end
|