Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 328
hworth Avatar asked Nov 04 '14 05:11

hworth


2 Answers

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.

like image 117
hworth Avatar answered Sep 22 '22 00:09

hworth


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
#...
like image 36
soundcorner Avatar answered Sep 18 '22 00:09

soundcorner