Han*_*nna 6 ruby ruby-on-rails railstutorial.org
我正在做 Hartle 教程,每次运行 rake 测试时都会看到此失败,我看到此失败:
1) Failure:
StaticPagesControllerTest#test_should_get_help [.../sample_app/test/controllers/static_pages_controller_test.rb:14]:
<Help | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.
Run Code Online (Sandbox Code Playgroud)
这是什么意思?我该如何解决?这是我的 static_pages_controller_test.rb 文件。
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
Run Code Online (Sandbox Code Playgroud)
这是第 14 行。
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
Run Code Online (Sandbox Code Playgroud)
问题是没有 html 匹配"Help | Ruby on Rails Tutorial Sample App"。
如果您查看 的定义assert_select,它接受:count作为(可选)参数。如果count未指定 ,则会将 的最小出现次数设置html为 1。这就是您收到的错误为 的原因Expected 0 to be >= 1.。在您的情况下,有 0 场比赛,而测试预计至少有 1 场比赛。
| 归档时间: |
|
| 查看次数: |
2587 次 |
| 最近记录: |