简体   繁体   中英

MiniTest Error: “NameError: uninitialized constant”

I'm following Michael Hartl's "Ruby on Rails Tutorial: Learn Web Development", and creating the tests that check a user's name and email for validity of length (name as a maximum of 50 chars, email as 255 chars). The contents of test/helpers/application_helper_test.rb are:

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

Upon running bundle exec rake test , all tests pass, but I see the following message flagged as an error at the end:

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>'

Any ideas how to fix this?

Turns out the issue is FILL_IN isn't the literal title (obviously), so it needs to be replaced with "Help | Ruby on Rails Tutorial Sample App", and "Ruby on Rails Tutorial Sample App" respectively. -Thanks to Nick Veys and p11y for this answer.

The FILL_IN constants can be replaced by :name, :email

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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