为什么我的测试框架无法找到在我的路由文件中定义的 URL?

Why is my test framework unable to find a URL defined in my routes file?

我正在使用 Rails 5 和 minutest 并尝试为控制器编写测试。测试是

# issues_controller_test.rb
class IssuesControllerTest < ActionDispatch::IntegrationTest

  include Devise::Test::IntegrationHelpers

  test "logged in should get issues page" do
    sign_in users(:one)
    test_stop_id = 1
    test_line_id = 1
    get new_issue, :stop_id => test_stop_id, :line_id => test_line_id
    assert_equal test_stop_id, @issue.stop_id
    assert_equal test_line_id, @issue.line_id
    assert_response :success
  end
end

有问题的方法试图访问这个页面,在我的 rails 路由中定义...

           new_issue GET      /issues/new(.:format)               issues#new

然而当我运行测试时,我得到这个错误

# Running:

.E

Error:
IssuesControllerTest#test_logged_in_should_get_issues_page:
NameError: undefined local variable or method `new_issue' for #<IssuesControllerTest:0x007f816759b330>
    test/controllers/issues_controller_test.rb:10:in `block in <class:IssuesControllerTest>'


bin/rails test test/controllers/issues_controller_test.rb:6



Finished in 0.103956s, 19.2389 runs/s, 9.6195 assertions/s.

为什么测试框架无法找到我的路由文件中定义的方法?

new_issue 这种方式只是一个局部变量,无处定义,请尝试将其指定为工作 url 和 new_issue_url:

test 'logged in should get issues page' do
  sign_in users :one
  test_stop_id = 1
  test_line_id = 1
  get new_issue_url, stop_id: test_stop_id, line_id: test_line_id
  assert_equal test_stop_id, @issue.stop_id
  assert_equal test_line_id, @issue.line_id
  assert_response :success
end