Sha256: 28742300015dab7baacc828e6e11ea6334f922f5f0218c14383e4fb584c31402

Contents?: true

Size: 1.32 KB

Versions: 54

Compression:

Stored size: 1.32 KB

Contents

require File.dirname(__FILE__) + '/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 < 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

Version data entries

54 entries across 53 versions & 9 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sinatra-1.0/test/route_added_hook_test.rb
adamwiggins-sinatra-0.10.1 test/route_added_hook_test.rb
sinatra-sinatra-0.10.0 test/route_added_hook_test.rb
sinatra-sinatra-0.10.1 test/route_added_hook_test.rb
sinatra-sinatra-0.9.1.3 test/route_added_hook_test.rb
sinatra-sinatra-0.9.2 test/route_added_hook_test.rb
sinatra-1.2.9 test/route_added_hook_test.rb
sinatra-base-1.0 test/route_added_hook_test.rb
sinatra-1.2.8 test/route_added_hook_test.rb
sinatra-1.2.7 test/route_added_hook_test.rb
sinatra-1.2.6 test/route_added_hook_test.rb
sinatra-1.3.0.d test/route_added_hook_test.rb
sinatra-1.3.0.c test/route_added_hook_test.rb
sinatra-1.2.3 test/route_added_hook_test.rb
sinatra-1.1.4 test/route_added_hook_test.rb
sinatra-1.2.2 test/route_added_hook_test.rb
sinatra-1.3.0.b test/route_added_hook_test.rb
sinatra-1.3.0.a test/route_added_hook_test.rb
sinatra-1.2.1 test/route_added_hook_test.rb
sinatra-1.2.0 test/route_added_hook_test.rb