2012-03-28 94 views
0

我正試圖在模塊化控制器中測試一個簡單的控制器操作。但是,我的get :index請求返回404而不是200響應。有沒有辦法跟蹤這個get請求的路由?跟蹤Rspec的控制器操作規範中的獲取請求路由

require "spec_helper" 

describe Admin::WidgetsController do 
    describe "GET index" do 
    it "has a 200 status code" do 
     get :index 
     response.code.should eq("200") 
    end 
    end 
end 

控制器看起來像你所期望的:

class Admin::WidgetsController < Admin::ApplicationController 
    respond_to :html, :xml, :json 
    def index 
    respond_with(@content = "content") 
    end 
end 

回答

0

聽上去好象什麼事不對您的路由。在控制檯上可以運行這個,看看有什麼途徑可供您的應用程序:

 $> rake routes 

我敢肯定下文中,當它失敗了,會告訴你什麼它被重定向到

describe Admin::WidgetsController do 
    describe "GET index" do 
    it "has a 200 status code" do 
     get :index 
     response.should redirect_to(:action => 'other_action') 
    end 
    end 
end 

您可以檢查這些鏈接,瞭解更多信息:

http://guides.rubyonrails.org/routing.html

http://old.rspec.info/rails/writing/controllers.html

+0

對不起,你實際上沒有重定向。相反,嘗試像這樣:'params_from(:get,「/ hello/world").should == {:controller =>」hello「,:action =>」world「}' – 2012-03-28 22:01:02

+0

上面設置了對路線的期望失敗應該會給你更多的信息。 – 2012-03-28 22:01:52

相關問題