MiniTest错误:“NameError:uninitialized constant”

时间:2014-11-04 05:19:45

标签: ruby-on-rails ruby rake minitest nameerror

我正在关注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>'

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

2 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:1)

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

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