【问题标题】:Ruby giving me similar four failures that other people have hadRuby 给了我与其他人类似的四次失败
【发布时间】:2015-11-02 01:40:16
【问题描述】:

我不断收到一些从其他人那里看到的错误。这是错误消息:

   1) Failure:
   StaticPagesControllerTest#test_should_get_about     [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:19]:
   <About | Ruby on Rails Tutorial Sample App> expected but was
   <About | Ruby on Rails Tutorial Sample App.>.
   Expected 0 to be >= 1.


   2) Failure:
   StaticPagesControllerTest#test_should_get_contact [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:25]:
   <Contact | Ruby on Rails Tutorial Sample App> expected but was
   <Contact | Ruby on Rails Tutorial Sample App.>.
   Expected 0 to be >= 1.


   3) Failure:
   StaticPagesControllerTest#test_should_get_help [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:13]:
   <Help | Ruby on Rails Tutorial Sample App> expected but was
   <Help | Ruby on Rails Tutorial Sample App.>.
   Expected 0 to be >= 1.


   4) Failure:
   StaticPagesControllerTest#test_should_get_home [C:/Sites/sample_app/test/controllers/static_pages_controller_test.rb:7]:
   <Home | Ruby on Rails Tutorial Sample App> expected but was
   <Ruby on Rails Tutorial Sample App.>.
   Expected 0 to be >= 1.

这里也是测试文件的代码:

 require 'test_helper'

 class StaticPagesControllerTest < ActionController::TestCase
   test "should get home" do
      get :home
      assert_response :success
      assert_select "title", "Ruby on Rails Tutorial Sample App"
   end

   test "should get help" do
      get :help
      assert_response :success
      assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
   end

   test "should get about" do
      get :about
      assert_response :success
      assert_select "title", "About | Ruby on Rails Tutorial Sample App"
   end

   test "should get contact" do
      get :contact
      assert_response :success
      assert_select "title", "Contact | Ruby on Rails Tutorial Sample App"
   end
 end

如何在我的应用程序中解决此问题?我是否必须为程序编写另一部分代码?

【问题讨论】:

  • 顺便说一下,页面确实与测试文件对应。
  • 然而,我似乎无法使用讨论中提供的信息来修复我的程序。
  • 您也可以使用我的一个有同样问题的朋友的这个链接。 stackoverflow.com/questions/33334767/…
  • 当有人要求查看产生错误的代码时,请不要只发布指向其他人代码的链接。这确实非常无益!

标签: ruby-on-rails ruby testing error-handling


【解决方案1】:

您应该尝试在测试中在Sample App 之后添加.(句点/句号),或者从您的视图中删除.

像这样:

test "should get home" do
  get :home
  assert_response :success
  assert_select "title", "Ruby on Rails Tutorial Sample App."
end

消息Expected 0 to be &gt;= 1 仅表示测试正在计算它可以在页面上找到内容(没有.)的次数,它计数为 0,但它预计计数至少为 1,因为这就是你在你的测试中断言。

【讨论】:

  • 这是 application.html.erb 文件的代码 true %> true %>
  • 您是否尝试过按照我在此答案中的建议进行操作?发生了什么?
  • 请将application.html.erb 文件的代码作为编辑发布在您的主帖中。这里绝对不是粘贴代码的地方。
猜你喜欢
  • 2014-08-15
  • 2012-05-17
  • 2019-03-24
  • 1970-01-01
  • 2021-07-19
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 2011-08-12
相关资源
最近更新 更多