Sha256: c6878ef7a9fa9fdcf6c360f133c918a50663befb0a586d3bde45efbfb392b387

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 KB

Contents

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 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

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
sinatra-acd-1.4.5 test/route_added_hook_test.rb
sinatra-1.4.5 test/route_added_hook_test.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/sinatra-1.4.4/test/route_added_hook_test.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/sinatra-1.4.4/test/route_added_hook_test.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/sinatra-1.4.4/test/route_added_hook_test.rb
sinatra-1.4.4 test/route_added_hook_test.rb
sinatra-1.4.3 test/route_added_hook_test.rb
sinatra-1.4.2 test/route_added_hook_test.rb
sinatra-1.4.1 test/route_added_hook_test.rb
sinatra-1.4.0 test/route_added_hook_test.rb
sinatra-1.4.0.d test/route_added_hook_test.rb
sinatra-1.4.0.c test/route_added_hook_test.rb
sinatra-1.4.0.b test/route_added_hook_test.rb
sinatra-1.4.0.a test/route_added_hook_test.rb
devcenter-0.0.3 vendor/sinatra/test/route_added_hook_test.rb
devcenter-0.0.2 vendor/sinatra/test/route_added_hook_test.rb
devcenter-0.0.1 vendor/sinatra/test/route_added_hook_test.rb