0

试图找出这个错误:

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 }) %>

和测试 - 我知道我需要在 before 块中有一个存根,但我不确定如何让 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
4

1 回答 1

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: "!")

谢谢

于 2013-08-18T11:02:28.267 回答