Sha256: 509c5574e677678fbdf30b5c228687aedcd461adde82beb293b6a1ad8a39dc78

Contents?: true

Size: 1.33 KB

Versions: 71

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

71 entries across 69 versions & 7 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.7.4 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.7.3 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/route_added_hook_test.rb
classiccms-0.7.2 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.7.1 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.7.0 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/route_added_hook_test.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/sinatra-1.3.5/test/route_added_hook_test.rb
sinatra-1.3.6 test/route_added_hook_test.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/sinatra-1.3.5/test/route_added_hook_test.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/route_added_hook_test.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/sinatra-1.3.5/test/route_added_hook_test.rb
sinatra-1.3.5 test/route_added_hook_test.rb
sinatra-1.3.4 test/route_added_hook_test.rb
classiccms-0.6.9 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.6.8 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.6.7 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
classiccms-0.6.6 vendor/bundle/gems/sinatra-1.3.2/test/route_added_hook_test.rb
jellyfish-0.5.0 sinatra/route_added_hook_test.rb