test/router_spec.rb in trellis-0.0.1 vs test/router_spec.rb in trellis-0.0.2

- old
+ new

@@ -1,52 +1,52 @@ require File.dirname(__FILE__) + '/spec_helper.rb' -describe Trellis::DefaultRouter, " when processing a request" do - before do - @regexp = Trellis::DefaultRouter::ROUTE_REGEX +describe Trellis::Router, " when constructed" do + + it "with a page parameter should route to that page " do + @router = Trellis::Router.new(:page => TestApp::Home) + @router.route().destination.should == TestApp::Home end - - it "should extract the page " do - value, source, event, destination = "/some_page".match(@regexp).to_a.reverse - value.should be_nil - source.should be_nil - event.should be_nil - destination.should_not be_nil - destination.should == "some_page" + + it "with a simple path it should match that path" do + request = mock('request', :path_info => '/hello') + @router = Trellis::Router.new(:path => '/hello') + @router.matches?(request).should be_true end - - it "should extract the page and event " do - value, source, event, destination = "/some_page.event".match(@regexp).to_a.reverse - value.should be_nil - source.should be_nil - event.should == "event" - destination.should_not be_nil - destination.should == "some_page" - end - - it "should extract the page, event and source " do - value, source, event, destination = "/some_page.event_source".match(@regexp).to_a.reverse - value.should be_nil - source.should == "source" - event.should == "event" - destination.should_not be_nil - destination.should == "some_page" - end - - it "should extract the page, event and source and value" do - value, source, event, destination = "/some_page.event_source/123".match(@regexp).to_a.reverse - value.should == "123" - source.should == "source" - event.should == "event" - destination.should_not be_nil - destination.should == "some_page" - end - it "should extract the page, event and value" do - value, source, event, destination = "/some_page.event/123".match(@regexp).to_a.reverse - value.should == "123" - source.should be_nil - event.should == "event" - destination.should_not be_nil - destination.should == "some_page" - end + it "with a path containing a single named parameter should match valid variations of that path" do + request_brian = mock('request', :path_info => '/hello/brian') + request_michael = mock('request', :path_info => '/hello/michael') + @router = Trellis::Router.new(:path => '/hello/:name') + @router.matches?(request_brian).should be_true + @router.matches?(request_michael).should be_true + end + + it "with a path containing multiple named parameters should match valid variations of that path" do + request_xmas = mock('request', :path_info => '/hello/2009/12/25') + request_labor_day = mock('request', :path_info => '/hello/2009/09/07') + @router = Trellis::Router.new(:path => '/hello/:year/:month/:day') + @router.matches?(request_xmas).should be_true + @router.matches?(request_labor_day).should be_true + end + + it "with a path containing a single named parameters should collect the parameter" do + @router = Trellis::Router.new(:path => '/hello/:name') + @router.keys.should include('name') + end + + it "with a path containing multiple parameters should collect all parameters" do + @router = Trellis::Router.new(:path => '/hello/:year/:month/:day') + @router.keys.should include('year', 'month', 'day') + end + + it "with a path containing multiple optional parameters should collect all parameters" do + @router = Trellis::Router.new(:path => '/?:foo?/?:bar?') + @router.keys.should include('foo', 'bar') + end + + it "with a path containing a single wildcard param it should capture the values in splat" do + @router = Trellis::Router.new(:path => '/*') + @router.keys.should include('splat') + end + end