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

问题描述 投票:1回答:1

我的测试一直在运行,直到我达到6.17。谁能帮我看看有什么不对?

这是错误并失败:

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文件:

class User < ApplicationRecord
  validates :name, presence: true, length: { maximum: 50 }
  validates :email, presence: true, length: { maxmium: 255 }
end

这是我的user_test.rb文件:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  def setup
    @user = User.new(name: "Example User", email: "[email protected]")
  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文件,因为它以某种方式涉及:

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

我已经将这些文件用于打字错误,似乎无法找到正在发生的事情。感谢您的任何帮助,您可以提供。

ruby-on-rails ruby railstutorial.org
1个回答
0
投票

对user.rb文件进行拼写检查。最大拼写错误最大值

代码应该是这样的

 class User < ApplicationRecord
      validates :name, presence: true, length: { maximum: 50 }
      validates :email, presence: true, length: { maximum: 255 }
 end
© www.soinside.com 2019 - 2024. All rights reserved.