我正在关注Michael Hartl的Ruby on Rails Tutorial。在 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.
有人请解释为什么我没有得到预期的测试结果。请注意,本教程中的实际部分有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
正如我之前提到的,它包含类似性质的额外测试。我之前只发布了这个类的片段。
控制器的View部分故意省略<title>
标记以使测试失败。例如,对于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>
答案 0 :(得分:1)
这可能是因为您使用的是Minitest内置的默认报告程序。 我看到了带有minitest-reporters gem的类似Minitest摘要: https://github.com/kern/minitest-reporters