Ruby on Rails 测试“预期响应但返回 200 [英] Ruby on Rails test "Expected response but returned 200

查看:26
本文介绍了Ruby on Rails 测试“预期响应但返回 200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名经验丰富的 Web 开发人员,我开始通过使用与 rails 代码绑定的 HTML 和 CSS 来学习 ruby​​ on rails.我有一个测试网站,正在尝试在 ruby​​ on rails 上运行它.该测试将在 web 上的一个 rails 应用程序下显示一个带有主页、帮助、关于和联系页面的网站.

I am an experienced web developer and am starting to learn ruby on rails with the use of HTML and CSS tied into the code for rails. I have a test website and am trying to run it on ruby on rails. The test will display a website with a home, help, about, and contact page under one rails application on the web.

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 :about
     assert_response :success
     assert_response "title, Contact | Ruby on Rails Tutorial Sample App"
  end

结束

但是,当我尝试在命令提示符下运行测试时,它在命令提示符下返回 3 次失败.每个失败都表明程序需要一种格式,但收到了另一种相同类型的格式.

However, when I try to run the test on the command prompt, it returns 3 failures on the command prompt. Each of the failures states that the program was expecting a format but received another format of the same type.

   FFF.

  Finished in 0.527144s, 7.5881 runs/s, 15.1761 assertions/s.

  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
   <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]:
Expected response to be a <title, Contact | Ruby on Rails Tutorial Sample App>, but was <200>.
--- expected
+++ actual
@@ -1 +1 @@
-"title, Contact | Ruby on Rails Tutorial Sample App"
+200



  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
    <Ruby on Rails Tutorial Sample App>.
    Expected 0 to be >= 1.

如何在程序中解决此问题?有没有办法让程序以正确的方式查看代码?如果一定要改,应该改成什么?

How do I fix this within the program? Is there a way to make the program view the code the correct way? If I have to change it, what should I change it to?

推荐答案

OK 所以这意味着没有 HTML 匹配请看这个答案:

OK so it means there is no HTML match please see this answer:

失败:预期为 0 >=1 在 ruby​​ on rails

这篇关于Ruby on Rails 测试“预期响应但返回 200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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