2011-09-15 81 views
2
it "should match login for existing account" do 
    { :get => 'http://www.' + @business.subdomain + '.lvh.me:3000/login' }.should route_to({:controller => "go", :action => "index"}) 
end 

match '/login' => 'admin/calendars#index' # this one should actually work, but fails: 

The recognized options <{"controller"=>"errors", "action"=>"handle404", "a"=>"login"}> did not match <{"controller"=>"go", "action"=>"index"}>, difference: <{"controller"=>"go", "action"=>"index", "a"=>"login"}>. 

這裏的特定的控制器#路線確實存在一個子目錄(或嵌套的路線),但目錄/嵌套路線(「管理/')似乎會導致失敗。考慮到那裏的指定路線('calendars#index')不存在,即使路線不存在,它也會以下一路線的方式失敗。結果路線的存在並不重要 - 因爲這只是爲了測試映射的工作原理。任何想法如何解決這個問題?RSpec的似乎打破時的路線「匹配」語句上市

match '/login' => 'calendars#index' #this one fails as expected: 

The recognized options <{"controller"=>"calendars", "action"=>"index"}> did not match <{"controller"=>"go", "action"=>"index"}>, difference: <{"controller"=>"go"}> 

回答

0

你的測試路線的建築是錯誤的:

it "should match login for existing account" do 
    { :get => 'http://www.' + @business.subdomain + '.lvh.me:3000/login' }.should route_to({:controller => "go", :action => "index"}) 
end 

或許應該閱讀:

it "should match login for existing account" do 
    { :get => 'http://' + @business.subdomain + '.lvh.me:3000/login' }.should route_to({:controller => "go", :action => "index"}) 
end 

的大概要測試http://foo.lvh.me/etchttp://www.foo.lvh.me