2012-03-26 68 views
0

我一直在寫一些rspec測試,現在我想驗證用戶創建後的重定向。許多其他測試工作,包括創建用戶。Rails Rspec路由錯誤當路由明顯存在

然而,最後下面的測試失敗:

describe "success" do 
    before(:each) do 
    @attr = { :username => "woweee123", 
       :email => "[email protected]", 
       :password => "password123", 
       :password_confirmation => "password123"} 
    end 

    it "should create the user" do 
      lambda do 
      post :create, :user => @attr 
      end.should change(User, :count) 
    end 

    it "should redirect to a user show page after creation" do 
     lambda do 
       post :create, :user => @attr 
     end.should redirect_to(user_path(assigns(:user))) 
    end 


    end 

失敗的測試是:沒有路由匹配{:動作=> 「秀」,:控制器=> 「用戶」

但,當我手動創建一個用戶(在localhost上)時,重定向顯然起作用。爲什麼這是失敗的?

回答

0

對於那些有興趣的回答是,我不得不改變測試,使其看起來像:

it "should redirect to a user show page after creation" do 
    post :create, :user => @attr 
    response.should redirect_to(user_path(assigns(:user))) 
end 

這工作。

0

我會檢查是否

assigns(@user).new_record? 

後門柱是不是真的了。好像它在你的測試中沒有ID。有些驗證失敗了嗎?