Skip to content

Instantly share code, notes, and snippets.

@bhb
Created December 13, 2009 23:20
Show Gist options
  • Save bhb/255665 to your computer and use it in GitHub Desktop.
Save bhb/255665 to your computer and use it in GitHub Desktop.
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