Unit testing 如何在小型测试中引用create方法来测试控制器?

Unit testing 如何在小型测试中引用create方法来测试控制器?,unit-testing,controller,routes,ruby-on-rails-5,minitest,Unit Testing,Controller,Routes,Ruby On Rails 5,Minitest,我正在使用Rails 5和minitest。如何在测试中引用createurl来测试控制器的create方法?在我的路由文件中,我有 resources :items test "do create" do person = people(:one) rating = 10 post items_create_url, params: {person_id: person.id, rating: rating} # Verify we got the pr

我正在使用Rails 5和minitest。如何在测试中引用createurl来测试控制器的create方法?在我的路由文件中,我有

resources :items
  test "do create" do
    person = people(:one)
    rating = 10
    post items_create_url, params: {person_id: person.id, rating: rating}

    # Verify we got the proper response
    assert_response :success
  end
在我的测试文件中,我有

resources :items
  test "do create" do
    person = people(:one)
    rating = 10
    post items_create_url, params: {person_id: person.id, rating: rating}

    # Verify we got the proper response
    assert_response :success
  end
然而,上述测试正在以失败告终

undefined local variable or method `items_create_url'

错误。在测试中引用我的create方法的正确方法是什么?

在RESTful路由中,模型被认为是事物的集合。在创建新项时,您正在将新项(数据)发布到现有项的集合中,因此Rails使用:

post items_url, params: {person_id: person.id, rating: rating}
有关路线的更多信息,Rails指南确实是最好的信息来源: