Agile Web Development Rails 5 test failures

本小妞迷上赌 提交于 2019-12-13 09:11:39

问题


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?

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/49735705/agile-web-development-rails-5-test-failures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!