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

pierre choffe
pierre choffe
20,501 Points

user_test unexpected error message

I keep getting this error whilst running ruby -Itest test/unit/user_test.rb :

test/unit/user_test.rb:13: syntax error, unexpected keyword_end, expecting $end

Cannot see where the error is :

class UserTest < ActiveSupport::TestCase test "a user should enter a first name" user = User.new assert !user.save assert !user.errors[:first_name].empty? end test "a user should enter a last name" user = User.new assert !user.save assert !user.errors[:last_name].empty? end <------ this is line 13 test "a user should enter a profile name" user = User.new assert !user.save assert !user.errors[:profile_name].empty? end test "a user should have a unique profile name" user = User.new user.profile_name = users(:pierre).profile_name assert !user.save assert !user.errors[:profile_name].empty? end end

Anyone had the same problem ? Thx, Pierre

12 Answers

pierre choffe
pierre choffe
20,501 Points

A more readable code :

class UserTest < ActiveSupport::TestCase

test "a user should enter a first name"

    user = User.new

    assert !user.save

    assert !user.errors[:first_name].empty?

end

test "a user should enter a last name"

    user = User.new

    assert !user.save

    assert !user.errors[:last_name].empty?

end                                                   <----- this is line 13

test "a user should enter a profile name"

    user = User.new

    assert !user.save

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

end

test "a user should have a unique profile name"

    user = User.new

    user.profile_name = users(:pierre).profile_name

    assert !user.save

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

end

end

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hi Pierre, your test methods need a "do" keyword after them on the end of the line. So the following:

test "a user should have a unique profile name"

Should be:

test "a user should have a unique profile name" do

Hope that helps!

pierre choffe
pierre choffe
20,501 Points

Ooooooooops !! thx Jason that did it :D Well I went through the whole user_test tut in order to test everything and now I get 5 errors (but no failure) :

1) Error: test_a_user_should_enter_a_first_name(UserTest): ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("first_name", "last_name", "profile_name", "email", "password", "password_confirmation", "created_at", "updated_at", "id") VALUES ('pierre', 'choffe', 'pierrechoffe', 'pc@xyz.com', 'password', 'password', '2013-02-19 22:21:36', '2013-02-19 22:21:36', 362712307)

2) Error: test_a_user_should_enter_a_last_name(UserTest):

3) Error: test_a_user_should_enter_a_profile_name(UserTest):

4) Error: test_a_user_should_have_a_profile_name_without_space(UserTest):

5) Error: test_a_user_should_have_a_unique_profile_name(UserTest):

The users.yml file has :

pierre: first_name: "pierre" last_name: "choffe" profile_name: "pierrechoffe" email: "pc@xyz.com" password: "password" password_confirmation: "password"

so i don't see what is wrong...

One last thing : when logging in on rails server, i don't understand what the profile name message means : what is wrong in the profile name format "pierre" ?

thanxxxx !! Pierre

Yeah I'm running into a test problem my self the output is 1) Failure: test_a_user_should_have_a_profile_na test.rb:34]: Failed assertion, no message given.

Can't find the flaw

(user._test.rb) line 34 assert user.errors[:profile_name].include?("Must be formatted correctly.")

(user.rb) validates :profile_name, presence: true, uniqueness: true, format: { with: /a-zA-Z0-9_-/, message: 'Must be formatted properly.' }

This is the validating format video, let me know if I'm missing something, thanks.

pierre choffe
pierre choffe
20,501 Points

I am now at the testing-the-whole-app/integration-tests I keep getting this error message (which is similar to the ones referred to in my previous message) when typing ruby -Itest test/integration/custom_routes_test.rb

1) Error: test_that_/_login_route_opens_the_login_page(CustomRoutesTest): ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("first_name", "last_name", "profile_name", "email", "password", "password_confirmation", "created_at", "updated_at", "id") VALUES ('pierre', 'choffe', 'pierrechoffe', 'pc@xyz.com', 'password', 'password', '2013-02-20 13:19:57', '2013-02-20 13:19:57', 362712307)

so I assume there is one common source to this series of error message, any idea ?

Thanks !!

pierre choffe
pierre choffe
20,501 Points

OK, pb #784 solved, apparently had to fix some additional information I had passed in users.yml also corrected a syntax error in user_test.rb : i had includes? instead of include? Alright, heading to pb #785 ! :)

pierre choffe
pierre choffe
20,501 Points

I get stuck in a new pb now in the "Testing the Profile Name" section.

When i type "ruby -Itest test/unit/user_test.rb" to test the profile name, I get the following message (2 failures) :

1) Failure: test_a_user_can_have_a_correctly_formatted_profile_name(UserTest) [test/unit/user_test.rb:45]: Failed assertion, no message given.

2) Failure: test_a_user_should_have_a_profile_name_without_spaces(UserTest) [test/unit/user_test.rb:37]: Failed assertion, no message given.

6 tests, 12 assertions, 2 failures, 0 errors, 0 skips

I could not see any flaw in my code, so I used Jason's code in Project Files, copying user_test.rb and user.rb, which are the two modified files in the video. After replacing the necessary details (name, etc.), I get exactly the same message.

What is wrong ? Thx, Pierre

Allen, I'm having the same problem as you. Have you figured it out? Or has anyone figure it out? I found another discussion about Allen and my problem if anyone could figure it out that would be great. My problem is just like Cassidy's on this forum (https://teamtreehouse.com/forum/writing-tests-validating-format)

I think I'm getting a similar problem to you guys, I'm running the integration tests in the "testing the whole app" and getting pages of 'detail'. The errors seem to be:

1) Error: test_that_/login_route_opens_the_login_page(CustomRoutesTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table statuses has no col
umn named name: INSERT INTO "statuses" ("name", "content", "created_at", "update
d_at", "id") VALUES ('MyString', 'MyText', '2013-04-15 05:03:32', '2013-04-15 05
:03:32', 980190962)

2) Error: test_that_/logout_route_opens_the_logout_page(CustomRoutesTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table statuses has no col
umn named name: INSERT INTO "statuses" ("name", "content", "created_at", "update
d_at", "id") VALUES ('MyString', 'MyText', '2013-04-15 05:03:32', '2013-04-15 05
:03:32', 980190962)

3) Error: test_that_/register_route_opens_the_logout_page(CustomRoutesTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table statuses has no col
umn named name: INSERT INTO "statuses" ("name", "content", "created_at", "update
d_at", "id") VALUES ('MyString', 'MyText', '2013-04-15 05:03:32', '2013-04-15 05
:03:32', 980190962)

I really don't know where I should check or what code to post.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Thomas, try opening up your test/fixtures/statuses.yml file and remove the "name" line from each status.

Ah thank you! Now I tried this and it didn't work - but then I cleared out the user.yml entirely and now my tests work. Much obliged!

had a similar issue. used a diff profile_name & email address in user_test.rb and it worked.