undefined local variable or method `api_v1_airlines' for #<AirlinesControllerTest:0x000000565ff5a928>

huangapple go评论67阅读模式
英文:

undefined local variable or method `api_v1_airlines' for #<AirlinesControllerTest:0x000000565ff5a928>

问题

I am not sure why minitest is not recognising my route:

# airlines_controller_test.rb
class AirlinesControllerTest &lt; ActionDispatch::IntegrationTest
    test &quot;should get index&quot; do
      get api_v1_airlines
      assert_response :success
    end
  end

` api_v1_airlines GET    /api/v1/airlines(.:format)                                                                        api/v1/airlines#index {:params=&gt;:slug}

I ran the test and it gave me

Error:
AirlinesControllerTest#test_should_get_index:
NameError: undefined local variable or method `api_v1_airlines' for #&lt;AirlinesControllerTest:0x0000006532df84b8&gt;
    test/controllers/airlines_controller_test.rb:5:in `block in &lt;class:AirlinesControllerTest&gt;&#39;

what am I doing wrong? It is not recognizing the route but it is defined in rails routes. What am I not including in my test file?

英文:

I am not sure why minitest is not recognising my route:

# airlines_controller_test.rb
class AirlinesControllerTest &lt; ActionDispatch::IntegrationTest
    test &quot;should get index&quot; do
      get api_v1_airlines
      assert_response :success
    end
  end

` api_v1_airlines GET    /api/v1/airlines(.:format)                                                                        api/v1/airlines#index {:params=&gt;:slug}

`

I ran the test and it gave me

`Error:
AirlinesControllerTest#test_should_get_index:
NameError: undefined local variable or method `api_v1_airlines&#39; for #&lt;AirlinesControllerTest:0x0000006532df84b8&gt;
    test/controllers/airlines_controller_test.rb:5:in `block in &lt;class:AirlinesControllerTest&gt;&#39;`

what am I doing wrong? It is not recognizing the route but it is defined in rails routes. What am I not including in my test file?

答案1

得分: 0

根据文档,应该使用路由助手的*_url形式。

class AirlinesControllerTest &lt; ActionDispatch::IntegrationTest
    test &quot;should get index&quot; do
      get api_v1_airlines_url
      assert_response :success
    end
  end
英文:

According to the docs, you should use the *_url form of the route helper.

class AirlinesControllerTest &lt; ActionDispatch::IntegrationTest
    test &quot;should get index&quot; do
      get api_v1_airlines_url
      assert_response :success
    end
  end

huangapple
  • 本文由 发表于 2023年5月7日 22:22:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定