Created
December 13, 2009 23:20
-
-
Save bhb/255665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
# Define a route | |
get "/foo" do | |
"x" | |
end | |
# Try to redefine it | |
get "/foo" do | |
"y" | |
end | |
def app | |
Sinatra::Application | |
end | |
# Require rack/test to get a convenient way to | |
# interact with the Sinatra routes | |
require "rack/test" | |
include Rack::Test::Methods | |
# Now make a GET request to /foo. Since routes | |
# are not overridden, this will print 'x', not 'y' | |
puts (get "/foo").body | |
# We can inspect the set of routes that Sinatra has. | |
# The output is: | |
#[/.*[^\/]$/, /^\/__sinatra__\/([^\/?&#]+)\.png$/, /^\/foo$/, /^\/foo$/] | |
# As you can see, the last two routes have a duplicate pattern | |
puts app.routes["GET"].map {|route| route.first}.inspect | |
set :run, false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment