2011-05-21 120 views
2

我在为我的一些路线编写规范时遇到了一些麻烦。我几乎遇到了这个问题,几乎所有的轨道匹配路线。下面的代码:Rails/RSpec匹配Rails匹配路线

在routes.rb中

match "/:id" => "home#order" 

在home_controller.rb

def order 
    respond_to do |format| 
    format.html { render :layout => 'order' } 
    end 
end 

在home_controller_spec.rb

it "should render the order layout" do 
    get :order 
    response.layout.should == 'layouts/order' 
end 

耙路线已:

/:id(.:format)      {:controller=>"home", :action=>"order"} 

然而,该规范是抛出此异常:

1) HomeController when not signed in should render the order layout 
    Failure/Error: get :order 
    ActionController::RoutingError: 
     No route matches {:controller=>"home", :action=>"order"} 

我在做什么错?

回答

2

我想,如果你使用命名路由

get :order 

只会工作。试试

get "/1"