test/unit/route_matcher_test.rb in merb-0.0.1 vs test/unit/route_matcher_test.rb in merb-0.0.2
- old
+ new
@@ -1,10 +1,15 @@
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/../../lib/merb'
-
+require 'set'
class RouteMatcherTest < Test::Unit::TestCase
+ def assert_same_hash(hsh1, hsh2)
+ assert_equal hsh1.keys.map(&:to_s).sort_by{|k| k}, hsh2.keys.map(&:to_s).sort_by{|k| k}
+ assert_equal hsh1.values.map(&:to_s).sort_by{|k| k}, hsh2.values.map(&:to_s).sort_by{|k| k}
+ end
+
def setup
Merb::RouteMatcher.prepare do |r|
r.add '/foo/:bar/baz/:id', :class => 'Test', :method => 'foo'
r.add '/hey/:there/you/:guys', :class => 'Test', :method => 'hello'
r.add '/these/:routes/are/:sweet', :class => 'Upload', :method => 'start'
@@ -23,31 +28,31 @@
assert( r.compiled_statement =~ /merge\(@sections\)/)
end
def test_route_matching
routes = Merb::RouteMatcher.new
- assert_equal( {:class=>"Test", :bar=>"123", :id=>"456", :method=>"foo"}, routes.route_request("/foo/123/baz/456"))
+ assert_same_hash( {:class=>"Test", :id =>"456", :bar =>"123", :method=>"foo"}, routes.route_request("/foo/123/baz/456"))
routes = Merb::RouteMatcher.new
- assert_equal( {:class=>"Test", :there=>"jon", :guys=>"girls", :method=>"hello"}, routes.route_request( "/hey/jon/you/girls"))
+ assert_same_hash( {:class=>"Test", :guys =>"girls", :there =>"jon", :method=>"hello"}, routes.route_request( "/hey/jon/you/girls"))
routes = Merb::RouteMatcher.new
- assert_equal({:class=>"upload", :id=>"12", :method=>"test"},routes.route_request( "/upload/test/12"))
+ assert_same_hash({:class=>"upload", :id=>"12", :method=>"test"},routes.route_request( "/upload/test/12"))
routes = Merb::RouteMatcher.new
- assert_equal({:class=>"nik", :method=>"nak"},routes.route_request( "/nik/nak"))
+ assert_same_hash({:class=>"nik", :method=>"nak"},routes.route_request( "/nik/nak"))
routes = Merb::RouteMatcher.new
- assert_equal({:class=>"lots", :method=>"of", :id => "12"},routes.route_request( "/lots/of/12"))
+ assert_same_hash({:class=>"lots", :method=>"of", :id => "12"},routes.route_request( "/lots/of/12"))
routes = Merb::RouteMatcher.new
- assert_equal({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/"))
+ assert_same_hash({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/"))
routes = Merb::RouteMatcher.new
- assert_equal({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/dfnasfnafn"))
+ assert_same_hash({:class => 'NoRouteFound', :method => 'noroute'},routes.route_request( "/dfnasfnafn"))
routes = Merb::RouteMatcher.new
- assert_equal( {:class=>"Upload", :routes=>"234", :sweet=>"yup", :method=>"start"}, routes.route_request( "/these/234/are/yup"))
+ assert_same_hash( {:class=>"Upload", :routes=>"234", :sweet=>"yup", :method=>"start"}, routes.route_request( "/these/234/are/yup"))
routes = Merb::RouteMatcher.new
- assert_equal( {:class=>"Test", :a=>"12", :c=>"red", :id=>"12", :f=>"blue"}, routes.route_request( '/h/12/b/red/d/blue/g/12'))
+ assert_same_hash( {:class=>"Test", :a=>"12", :c=>"red", :id=>"12", :f=>"blue"}, routes.route_request( '/h/12/b/red/d/blue/g/12'))
end
def test_route_doesnt_match
routes = Merb::RouteMatcher.new
- assert_equal({:class=>"NoRouteFound", :method=>"noroute"},routes.route_request( '/hdsfvsdfsdfdsf'))
+ assert_same_hash({:class=>"NoRouteFound", :method=>"noroute"},routes.route_request( '/hdsfvsdfsdfdsf'))
end
def test_regexes_included_in_compiled_statement
routes = Merb::RouteMatcher.new
routes.routes.each do |r|