Ruby给了我其他人类似的四次失败

时间:2015-11-02 01:40:17

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

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

   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

如何在我的应用程序上修复此问题?我是否必须为该程序编写另一部分代码?

1 个答案:

答案 0 :(得分: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 >= 1只是意味着测试计算了在页面上找到内容(没有.)的次数,并且计数为0,但预计计数至少为1因为这是你在测试中断言的。