NameError:未初始化的常量ApplicationHelperTest :: Fill_IN

时间:2016-01-21 06:50:20

标签: ruby-on-rails ruby-on-rails-3

当我从Ruby on Rails Tutorial中添加此代码中的最后一个测试时,从列表6.11和6.12然后运行bundle exec rake测试我得到此错误消息列表6.13我正在运行Linux Xubuntu

  

1)错误:       ApplicationHelperTest#test_full_title_helper:       NameError:未初始化的常量ApplicationHelperTest :: FILL_IN           test / helpers / application_helper_test.rb:5:在`block in'

当我删除电子邮件验证时,测试通过。

测试/模型/ user_test.rb

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  
end

应用程序/模型/ user.rb

class User < ActiveRecord::Base
  validates :name,  presence: true
  validates :email, presence: true
end

我认为它必须与Application Helper有关。这是助手中的代码:

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

1 个答案:

答案 0 :(得分:3)

这是因为测试试图寻找一个名为FILL_IN的常量,它不存在。本教程要求您将FILL_IN替换为正确的值。