敏捷 Web 开发 Rails 5 测试失败 [英] Agile Web Development Rails 5 test failures

查看:39
本文介绍了敏捷 Web 开发 Rails 5 测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从 Agile Web Development with Rails 5 教科书中创建了 Depot 应用程序.出于某种原因,我收到错误消息 &运行rails 测试"时失败.有人可以解释为什么会这样吗?

I just finished creating the Depot app from the Agile Web Development with Rails 5 textbook. For some reason, I am getting errors & failures when I run 'rails test'. Can someone explain why this is happening?

我的 Github 存储库在这里:https://github.com/christopheragnus/Agile_Web_Development_with_Rails_5>

My Github repository is here: https://github.com/christopheragnus/Agile_Web_Development_with_Rails_5

Christophers-MacBook-Pro-3:depot Agnus$ rails test
Running via Spring preloader in process 45997
Run options: --seed 52040

# Running:

..............F

Failure:
LineItemsControllerTest#test_should_create_line_item [/Users/Agnus/Dropbox/CA/AgileWebDevelopment/depot/test/controllers/line_items_controller_test.rb:25]:
<Your Cart> expected but was
<>..
Expected 0 to be >= 1.


bin/rails test test/controllers/line_items_controller_test.rb:18

..E

Error:
OrderMailerTest#test_shipped:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b60cc410>
Did you mean?  login_as
    test/test_helper.rb:12:in `login_as'
    test/test_helper.rb:20:in `setup'


bin/rails test test/mailers/order_mailer_test.rb:12

E

Error:
OrderMailerTest#test_received:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b6058880>
Did you mean?  login_as
    test/test_helper.rb:12:in `login_as'
    test/test_helper.rb:20:in `setup'


bin/rails test test/mailers/order_mailer_test.rb:4

E

Error:
AdminControllerTest#test_should_get_index:
NameError: undefined local variable or method `admin_index_url' for #<AdminControllerTest:0x007ff7b4ca8880>
    test/controllers/admin_controller_test.rb:5:in `block in <class:AdminControllerTest>'


bin/rails test test/controllers/admin_controller_test.rb:4

...........................

Finished in 5.740751s, 8.1871 runs/s, 14.4580 assertions/s.
47 runs, 83 assertions, 1 failures, 3 errors, 0 skips

推荐答案

未定义错误意味着:您正在调用login_url"但 rails 无法在任何地方找到它.如果您只是从书中复制粘贴的代码,您应该转到他们创建此帮助文件的部分并查看他们定义 login_url 的位置.

The undefined errors mean just that: you are calling "login_url" but rails cannot find it anywhere. If you simply copy pasted code from the book you should go to the section where they create this helper file and see where they defined the login_url.

与错误相反,测试失败是它期望存在名为Your Cart"的 h2 元素,但找不到它.要对此进行调试,您可以检查代码并确保所有路由/重新路由都正确,并且视图结构正确且没有错别字 - 或者运行应用程序并完成测试正在执行的操作并查看结果你看到的是预期的.然后——我们可以从那里出发.

The test failure, opposed to the error, is that it is expecting an h2 element to exist with the name "Your Cart" but it cannot find it. To debug this, you could either go through the code and make sure all the routing/rerouting is correct and that the views are correctly structured and there's no typos- or run the app and go through what the test is doing and see if the results you are seeing is what is expected. Then- we can go from there.

根据经验,养成使用谷歌搜索错误的习惯是很好的,这可以帮助您了解在何处解决项目中的问题.

As a rule of thumb, it is good to get into the habit of googling errors which can help give you an idea of where to troubleshoot the issues in your project.

这篇关于敏捷 Web 开发 Rails 5 测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆