Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Writing Tests Fixtures

Andrew Rice
Andrew Rice
2,233 Points

NoMethodError on tests

I am at the end of the fixtures video, and I get this error:

Error:UserTest#test_user_should_have_a_unqiue_profile_name:
NoMethodError: undefined method 'empty?' for ["has already been taken"]:Array
   test/models/user_test.rb:30:in 'block in <class:UserTest>'

And here is my UserTest class:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
  test "a user should enter a first name" do
    user = User.new
    assert !user.save
    assert !user.errors[:first_name].empty?
  end

    test "a user should enter a last name" do
    user = User.new
    assert !user.save
    assert !user.errors[:last_name].empty?
  end

    test "a user should enter a profile name" do
    user = User.new
    assert !user.save
    assert !user.errors[:profile_name].empty?
  end

  test "user should have a unique profile name" do
    user = User.new
    user.profile_name = users(:andrew).profile_name

    assert !user.save
    assert !user.errors[:profile_name].emtpy?
  end

end

2 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hey Andrew,

You have a typo on this line:

 assert !user.errors[:profile_name].emtpy?