2012-03-26 69 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。有些验证失败了吗?