簡體   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