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

   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

如何在应用程序上解决此问题?我是否需要为该程序编写另一部分代码?

最佳答案

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

像这样:

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

消息Expected 0 to be >= 1只是意味着测试正在计算它可以在页面上找到内容的次数(没有.),并且计数为0,但是它期望计数至少为1,因为这就是您在测试中所断言的内容。

08-25 15:09