user1221866
user1221866

Reputation: 13

Ruby on Rails testing - NameError: uninitialized constant

I'm getting the following errors when trying to run tests:

Using Rails 3.2.1

$ rake test Run options:

Running tests:

EEEEEEEEEE

Finished tests in 0.012787s, 782.0346 tests/s, 0.0000 assertions/s.

1) Error: test_user_entry_no_email(UserTest): NameError: uninitialized constant UserTest::Users /home/nowobil1/projectDresser/test/unit/user_test.rb:12:in `block in '

2) Error: test_user_entry_no_username(UserTest): NameError: uninitialized constant UserTest::Users /home/nowobil1/projectDresser/test/unit/user_test.rb:18:in `block in '

3) Error: test_valid_user_entry,_only_username_and_email(UserTest): NameError: uninitialized constant UserTest::Users /home/nowobil1/projectDresser/test/unit/user_test.rb:5:in `block in '

3 tests, 0 assertions, 0 failures, 3 errors, 0 skips

Here is my test file:

    1 require 'test_helper'¬                                                                                                                                    
    2 ¬
    3 class UserTest < ActiveSupport::TestCase¬
    4    test "valid user entry, only username and email" do¬
    5       user = Users.new¬
    6       user.username = "testUser1"¬
    7       user.email = "[email protected]"¬
    8       assert user.save, "Saved a valid user entry"¬
    9    end¬
   10 ¬
   11   test "user entry no email" do¬
   12       user = Users.new¬
   13       user.username = "testUser2"¬
   14       assert !user.save, "Saved a user without email"¬
   15   end¬
   16 ¬
   17   test "user entry no username" do¬
   18       user = Users.new¬
   19       user.email = "[email protected]"¬
   20       assert !user.save, "Saved a user without username"¬
   21   end¬
   22 end¬

Upvotes: 1

Views: 2302

Answers (2)

theIV
theIV

Reputation: 25774

Based on conventional naming, your model will be named User, not Users (however, your table is named users).

Try replacing Users with User on lines 5, 12, and 18.

Upvotes: 1

iltempo
iltempo

Reputation: 16012

Use User instead of Users in your tests pls.

Upvotes: 0

Related Questions