失败:预期 0 在 ruby​​ on rails 上 >= 1 [英] Failure: Expected 0 to be >= 1 on ruby on rails

查看:28
本文介绍了失败:预期 0 在 ruby​​ on rails 上 >= 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做 Hartle 教程,每次运行 rake 测试时都会看到此失败:

I'm doing Hartle tutorial and see this failure every time I run rake test I see this failure:

  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.

什么意思?我该如何解决?这是我的 static_pages_controller_test.rb 文件.

What does it mean? And how can I solve it? This is my static_pages_controller_test.rb file.

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

这里是第 14 行.

assert_select "title", "Help | Ruby on Rails Tutorial Sample App"

推荐答案

问题是没有html匹配Help | Ruby on Rails Tutorial Sample App".

The issue is that there is no html matching "Help | Ruby on Rails Tutorial Sample App".

如果您查看 assert_select 的定义,它接受 :count 作为(可选)参数.如果未指定 count,它会将 html 的最小出现次数设置为 1.这就是为什么您得到的错误是 Expected 0 to be >= 1..在您的情况下,有 0 个匹配项,而测试预计至少有 1 个匹配项.

if you look at the definition of assert_select, it accepts :count as (optional) argument. If the count is not specified, it sets the minimum occurrence of the html to 1. This is why the error you are getting is Expected 0 to be >= 1.. In your case there were 0 matches where the test expected at least 1 match.

这篇关于失败:预期 0 在 ruby​​ on rails 上 >= 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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