2013-08-18 29 views
0

试图找出此错误:如何在rspec中存储此方法?

ActionView::Template::Error: 
     No route matches 
     {:controller=>"evaluations", 
      :action=>"note", 
      :student_group_id=># 
      <StudentGroup id: 2, 
      name: "Rainbow Class", 
      user_id: 1, 
      created_at: "2013-08-18 10:45:46", 
      updated_at: "2013-08-18 10:45:46", 
      number_of_students: nil, 
      type_of_group: "Adult class (18+)">, 
      :student_id=>nil} 

能正常工作在浏览器中,它只是在测试中失败。

下面的代码:

<%= link_to "!", eval_note_path({ student_group_id: @student_group, student_id: @student_group.students.first }) %> 

和测试 - 我知道我需要在一个枝节块之前,但我不知道如何使rspec的做我想做的。环顾四周,对左右,但磕碰似乎相当依赖的情况下,我无法弄清楚:

describe "GET 'index" do 

    before(:each) do 
    @index = get :index 
    @student_group.stub(:students.first).and_return(1)  
    end 

    ... 

    it "should have an evaluation link" do 
    @index 
    response.should have_selector('a', 
            href: eval_note_path({ 
             student_group_id: @student_group, 
             student_id: @student 
             }), 
            content: "!") 
    end 

end 

回答

0

尝试用@student_group.id它应该工作。

it "should have an evaluation link" do 
    @index 
    response.should have_selector('a', 
            href: eval_note_path({ 
             student_group_id: @student_group.id, 
             student_id: @student 
             }), 
            content: "!") 

感谢

+0

了'student_group_id'是好的 - 那就是获取返回'nil' – dax

+0

,因为你的学生对象是零只有'student_id'。你必须在每个块之前存储你的学生对象。 –

+0

我采取了阻力最小的路径,只是改变了路线路径 - 我可以在稍后传递'student_id'而没有大问题。谢谢! – dax