首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hartl Rails教程,第6章,清单6.17测试失败

Hartl Rails教程,第6章,清单6.17测试失败
EN

Stack Overflow用户
提问于 2018-01-04 00:24:11
回答 1查看 146关注 0票数 1

在我达到6.17之前,我的测试一直在变绿。有人能帮我看看是怎么回事吗?

以下是错误和失败:

代码语言:javascript
复制
ERROR["test_layout_links", SiteLayoutTest, 0.011797307059168816]
 test_layout_links#SiteLayoutTest (0.01s)
ArgumentError:         ArgumentError: Range unspecified. Specify the :in, 
:within, :maximum, :minimum, or :is option.
        app/models/user.rb:3:in `<class:User>'
        app/models/user.rb:1:in `<top (required)>'

 FAIL["test_email_should_not_be_too_long", UserTest, 0.04466394800692797]
 test_email_should_not_be_too_long#UserTest (0.04s)
    Expected true to be nil or false
    test/models/user_test.rb:29:in `block in <class:UserTest>'

12/12: [=============================================================] 100% 
Time: 00:00:00, Time: 00:00:00

Finished in 0.62805s
12 tests, 15 assertions, 1 failures, 1 errors, 0 skips

这是我的user.rb文件:

代码语言:javascript
复制
class User < ApplicationRecord
  validates :name, presence: true, length: { maximum: 50 }
  validates :email, presence: true, length: { maxmium: 255 }
end

这是我的user_test.rb文件:

代码语言:javascript
复制
require 'test_helper'

class UserTest < ActiveSupport::TestCase
  def setup
    @user = User.new(name: "Example User", email: "user@example.com")
  end

  test "should be valid" do
    assert @user.valid?
  end

  test "name should be present" do
    @user.name = "     "
    assert_not @user.valid?
  end

  test "email should be present" do
    @user.email = "     "
    assert_not @user.valid?
  end

  test "name should not be too long" do
    @user.name = "a" * 51
    assert_not @user.valid?
  end

  test "email should not be too long" do
    @user.email = "a" * 244 + "@example.com"
    assert_not @user.valid?
  end
end

这是我的site_layout_test.rb文件,因为它是以某种方式涉及到的:

代码语言:javascript
复制
require 'test_helper'

class SiteLayoutTest < ActionDispatch::IntegrationTest

 test "layout links" do
   get root_path
   assert_template 'static_pages/home'
   assert_select "a[href=?]", root_path, count: 2
   assert_select "a[href=?]", help_path
   assert_select "a[href=?]", about_path
   assert_select "a[href=?]", contact_path
   get contact_path
   assert_select "title", full_title("Contact")
   get signup_path
   assert_select "title", full_title("Sign Up")
 end
end

我已经对这些文件进行了排印,似乎找不到正在发生的事情。谢谢你能提供的任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-04 04:37:53

user.rb文件进行拼写检查。您错选了maximum for for

代码应该是

代码语言:javascript
复制
 class User < ApplicationRecord
      validates :name, presence: true, length: { maximum: 50 }
      validates :email, presence: true, length: { maximum: 255 }
 end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48087048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档