2011-04-19 90 views
2

我创建了一个名为PolicyController控制器和嵌套像这样的路线:如何在使用Rspec进行测试时处理RoutingError?

scope "/your" 
    resources :shops do 
     resources :policies 
    end 
    end 

现在,当我试图测试这个控制器我不断收到此错误:

1) PoliciesController POST 'create' should be successful 
    Failure/Error: post 'create' 
    ActionController::RoutingError: 
     No route matches {:controller=>"policies", :action=>"create"} 
    # ./spec/controllers/policies_controller_spec.rb:7:in `block (3 levels) in <top (required)>' 

不知道如何设置对的。将不胜感激的帮助。

编辑:忘记我的规格:

describe PoliciesController do 
    describe "POST 'create'" do 
    it "should be successful" do 
     post 'create' 
     response.should be_success 
    end 
end 
+0

请张贴您的规格,从它的外观你正在使用获取创建操作,它应该是一个职位。 – Shiv 2011-04-19 22:19:54

+0

我改变了发表,但它似乎没有区别。 – picardo 2011-04-19 22:31:34

回答

4

你认为这是否行得通呢?

post :create, :shop_id => 1 

绝对要在前一个街区创建一个新店。