繁体   English   中英

MiniTest错误:“NameError:uninitialized constant”

[英]MiniTest Error: “NameError: uninitialized constant”

我正在关注Michael Hartl的“Ruby on Rails教程:学习Web开发”,并创建检查用户姓名和电子邮件的测试长度的有效性(名称最多50个字符,电子邮件为255个字符)。 test/helpers/application_helper_test.rb的内容是:

require 'test_helper'

class ApplicationHelperTest < ActionView::TestCase
  test "full_title_helper" do
    assert_equal full_title,         FILL_IN
    assert_equal full_title("Help"), FILL_IN
  end
end

运行bundle exec rake test ,所有测试都通过,但我看到以下消息在结尾处标记为错误:

ERROR["test_full_title_helper", ApplicationHelperTest, 1.820016791]
test_full_title_helper#ApplicationHelperTest (1.82s)
NameError:         NameError: uninitialized constant ApplicationHelperTest::FILL_IN
        test/helpers/application_helper_test.rb:5:in `block in <class:ApplicationHelperTest>'
    test/helpers/application_helper_test.rb:5:in `block in <class:ApplicationHelperTest>'

任何想法如何解决这一问题?

事实证明,问题是FILL_IN不是文字标题(显然),因此需要分别用“帮助| Ruby on Rails教程示例应用程序”和“Ruby on Rails教程示例应用程序”替换。 - 感谢Nick Veys和p11y的回答。

FILL_IN常量可以替换为:name,:email

class User < ActiveRecord::Base
#...
has_many :microposts
validates :name, presence: true
validates :email, presence: true
#...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM