Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails测试,获取失败:…预期0为>;=1._Ruby On Rails_Ruby_Minitest_Railstutorial.org - Fatal编程技术网

Ruby on rails rails测试,获取失败:…预期0为>;=1.

Ruby on rails rails测试,获取失败:…预期0为>;=1.,ruby-on-rails,ruby,minitest,railstutorial.org,Ruby On Rails,Ruby,Minitest,Railstutorial.org,我在跟随迈克尔·哈特尔的。在第3.4.1节测试标题(红色)中,作者使用assert_select viz编写了一个小型测试 test "should get home" do get static_pages_home_url assert_select "title", "Home | Ruby on Rails Tutorial Sample App" end 然后,他希望在运行rails测试时得到以下输出: 1 tests, 1 assertions, 1 failures, 0

我在跟随迈克尔·哈特尔的。在第3.4.1节测试标题(红色)中,作者使用assert_select viz编写了一个小型测试

test "should get home" do
  get static_pages_home_url
  assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
end
然后,他希望在运行rails测试时得到以下输出:

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
但是,当我在本地系统上运行完全相同的测试时,会收到以下失败消息:

# Running:

FF

Failure:
StaticPagesControllerTest#test_should_get_home [/Users/gurpreet/environment/sample_app/test/controllers/static_pages_controller_test.rb:7]:
<Home | Ruby on Rails Tutorial Sample App> expected but was
<SampleApp>..
Expected 0 to be >= 1.
#运行:
FF
失败:
StaticPagesControllerTest#test(测试)应(返回)[/Users/Gurpret/environment/sample(示例)app/test/controllers/static(测试)pages(控制器)test.rb
预料之中,但事实并非如此
..
预期0大于等于1。
有人请解释为什么我没有得到预期的rails测试结果。请注意,教程中的实际部分有3个测试和6个断言,但我刚刚发布了相关的详细信息,其中使用了单测试和单断言

以下是完整的控制器测试类:

require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test "should get home" do
    get static_pages_home_url
    assert_response :success
    assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
  end

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

  test "should get about" do
    get static_pages_about_url
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App"
  end
end
需要“测试助手”
类StaticPagesControllerTest
正如我前面提到的,它包含类似性质的额外测试。我之前只发布了这个类的一个片段

控制器的视图部分故意省略
标记,使测试失败。例如,在home.html.erb的情况下

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <h1>Sample App</h1>
    <p>
      This is the home page for the
      <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
      sample application
    </p>
  </body>
</html>

示例应用程序

这是网站的主页
示例应用程序


这可能是因为您使用的是内置于Minitest中的默认报告程序。 我在Minitest reporters gem上看到了类似的Minitest摘要:

你能上传你正在测试的类吗?Hartl正在教你测试驱动开发,你可以编写一个你认为会失败的测试,然后编写代码让它通过。当测试失败时,您会得到一个失败原因的概要,然后您会得到一个摘要行,计算通过和失败的测试数量。现在添加
标签并通过测试@Phlip您是对的,我还希望测试失败,因为没有
标记。问题是,在教程中,测试结束时有一个很好的摘要行,显示了失败测试的数量,但在我的例子中,没有摘要行,测试似乎在第一次失败时停止。谢谢@wondersz1,但我无法确认它是否有效,因为我现在已经离开Ruby on Rails。