* Only add :format to routes if otherwise not explicitly set.
[sinatra.git] / test / sinatra / route_test.rb
blob9681720af22fc057049b83ff83a644e7cd53e5fd
1 require File.dirname(__FILE__) + '/../helper'
3 describe "Route" do
4   it "gives :format for free" do
5     route = Sinatra::Route.new('/foo/:test/:blake')
7     route.recognize('/foo/bar/baz').should.equal true
8     route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'html'
10     route.recognize('/foo/bar/baz.xml').should.equal true
11     route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'xml'
12   end
13   
14   it "doesn't auto add :format for routes with explicit formats" do
15     route = Sinatra::Route.new('/foo/:test.xml')
16     route.recognize('/foo/bar').should.equal false
17     route.recognize('/foo/bar.xml').should.equal true
18     route.params.should.equal :test => 'bar', :format => 'xml'
19   end
21 end