Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby User Authentication with Rails Password Hashing and Sign In Creating the User Model: Part 1

John Simoneau
PLUS
John Simoneau
Courses Plus Student 8,105 Points

3 Failures I could use help with...

I'm getting 3 failures when I do a rake at the start of the User Authentication course and can't seem to figure them out.

  1) Viewing todo items is successful with valid content
     Failure/Error: within("table.todo_items") do
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching css "table.todo_items"
     # ./spec/features/todo_items/create_spec.rb:12:in `block (2 levels) in <top (required)>'

  2) Viewing todo items displays the title of the todo list
     Failure/Error: within("h1") do
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching css "h1"
     # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

  3) Viewing todo items displays item content when a todo list has items
     Failure/Error: expect(page.all("ul.todo_items li").size).to eq(2)

       expected: 2
            got: 0

       (compared using ==)
     # ./spec/features/todo_items/index_spec.rb:24:in `block (2 levels) in <top (required)>'

I'm still figuring out github but think I got my files uploaded and a branch with recent file changes via the link below.

https://github.com/jsimoneau2015/ODOT/tree/Start-of-User-Authentication-Course

Thanks for any help with this!

3 Answers

Tom Sager
Tom Sager
18,987 Points

Yes, this is caused by the second h1 that 'snuck in' from the from the layout file. The file app/views/layouts/application.html.erb is automatically rendered on every page.

The easiest way to fix this would be to get rid of the scope altogether:

it "displays the title of the todo list" do
  visit_todo_list(todo_list)
  expect(page).to have_content(todo_list.title)
end

Or you can add a class or id to the title:

<h1 class='todoListTitle'><%= @todo_list.title %></h1>

it "displays the title of the todo list" do
  visit_todo_list(todo_list)
  within('.todoListTitle') do
    expect(page).to have_content(todo_list.title)
  end
end
John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

yes! Fixed! Thank you so much! Now I can finally get back going with the last part of this track before going back and rewatching it all to sink everything in more...LOL.

Tom Sager
Tom Sager
18,987 Points

For the first message, your todo_items index view has a duplicated table definition on lines 3 and 4:

<table class="todo_items">
  <table class="todo_items">

<p>The other two messages don't seem to match up with the code you posted on github, and the spec files there do not match any of these tests.</p> <p>Look for similar duplicates in your view file. If you are still having problems, try pushing a more current version to github, or post more details of your rspec output here.</p>

John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

Ok, first... I feel like an idiot over that duplicate element. I was thinking way too hard about things when it was telling me the exact issue right in the error...LOL.

I've fixed that and the #3. I'm still having issues with #2 though. I can't figure out what it is...

The github files should be exactly what I'm using right now in Sublime. You should be able to verify by seeing my latest updates added I think (titled bug fixes). Hopefully you can help me based off that but I'm willing to post whatever you or anyone needs. I'm just not sure what other details exactly to post.

Thank you so much for the help!

Tom Sager
Tom Sager
18,987 Points

We all make small errors like that. I was look for the tests in the spec directory, but I now see them in spec/features. Even though the correct path was right there in the error message! :-)

I do not see an obvious error. Do you have a more detailed error message you can post? If not, try adding the following to your .rspec file:

--require spec_helper
--format documentation --format html --out coverage/rspec_results.html

and / or add to your test:

visit_todo_list(todo_list)
  save_and_open_page
  within("h1") do

Either of these should provide some good diagnostic information.

John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

I've added that first thing. The second required installing a gem etc.

Here is the test results

/home/treehouse/.rbenv/versions/2.0.0-p353/bin/ruby -S rspec ./spec/controllers/todo_items_controller_spec.rb ./spec/controllers/todo_lists_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/features/todo_items/complete_spec.rb ./spec/features/todo_items/create_spec.rb ./spec/features/todo_items/delete_spec.rb ./spec/features/todo_items/edit_spec.rb ./spec/features/todo_items/index_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_spec.rb ./spec/helpers/todo_items_helper_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/helpers/users_helper_spec.rb ./spec/models/todo_item_spec.rb ./spec/models/todo_list_spec.rb ./spec/models/user_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/routing/users_routing_spec.rb ./spec/views/todo_items/index.html.erb_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb ./spec/views/users/edit.html.erb_spec.rb ./spec/views/users/new.html.erb_spec.rb ./spec/views/users/show.html.erb_spec.rb failed
treehouse:~/projects/odot (Start-of-User-Authentication-Course *) $ bin/rake
/home/treehouse/.rbenv/versions/2.0.0-p353/bin/ruby -S rspec ./spec/controllers/todo_items_controller_spec.rb ./spec/controllers/todo_lists_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/features/todo_items/complete_spec.rb ./spec/features/todo_items/create_spec.rb ./spec/features/todo_items/delete_spec.rb ./spec/features/todo_items/edit_spec.rb ./spec/features/todo_items/index_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_spec.rb ./spec/helpers/todo_items_helper_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/helpers/users_helper_spec.rb ./spec/models/todo_item_spec.rb ./spec/models/todo_list_spec.rb ./spec/models/user_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/routing/users_routing_spec.rb ./spec/views/todo_items/index.html.erb_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb ./spec/views/users/edit.html.erb_spec.rb ./spec/views/users/new.html.erb_spec.rb ./spec/views/users/show.html.erb_spec.rb

TodoListsController
  DELETE destroy
    destroys the requested todo_list
    redirects to the todo_lists list
  GET new
    assigns a new todo_list as @todo_list
  GET show
    assigns the requested todo_list as @todo_list
  POST create
    with valid params
      creates a new TodoList
      redirects to the created todo_list
      assigns a newly created todo_list as @todo_list
    with invalid params
      assigns a newly created but unsaved todo_list as @todo_list
      re-renders the 'new' template
  PUT update
    with valid params
      updates the requested todo_list
      redirects to the todo_list
      assigns the requested todo_list as @todo_list
    with invalid params
      assigns the todo_list as @todo_list
      re-renders the 'edit' template
  GET index
    assigns all todo_lists as @todo_lists
  GET edit
    assigns the requested todo_list as @todo_list

Creating todo lists
  displays an error when the todo list has a title less than 3 characters
  displays an error when the todo list has no title
  displays an error when the todo list has no description
  displays an error when the todo list has a title less than 5 characters
  redirects to the todo list index page on success

Editing todo lists
  displays an error too short of a title
  displays an error with no title
  displays an error with no description
  displays an error too short of a description
  updates a todo list successfully with correct information

todo_lists/new
  renders new todo_list form

UsersController
  POST create
    with valid params
      creates a new User
      redirects to the created user
      assigns a newly created user as @user
    with invalid params
      assigns a newly created but unsaved user as @user
      re-renders the 'new' template
  GET edit
    assigns the requested user as @user
  PUT update
    with valid params
      updates the requested user
      redirects to the user
      assigns the requested user as @user
    with invalid params
      assigns the user as @user
      re-renders the 'edit' template
  DELETE destroy
    destroys the requested user
    redirects to the users list
  GET new
    assigns a new user as @user

Viewing todo items
  displays the title of the todo list (FAILED - 1)
  displays item content when a todo list has items
  displays no items when a todo list is empty

users/new
  renders new user form

UsersHelper
  add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/users_helper_spec.rb (PENDING: No reason given)

UsersController
  routing
    routes to #destroy
    routes to #show
    routes to #new
    routes to #create
    routes to #update
    routes to #index
    routes to #edit

Deleting todo items
  is successful

TodoItemsHelper
  add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/todo_items_helper_spec.rb (PENDING: No reason given)

todo_lists/edit
  renders the edit todo_list form

Deleting todo lists
  is successful when clicking the destroy link

Editing todo items
  is successful with valid content
  is unsuccessful with not enough content
  is unsuccessful with no content

todo_items/index.html.erb
  add some examples to (or delete) /home/treehouse/projects/odot/spec/views/todo_items/index.html.erb_spec.rb (PENDING: No reason given)

TodoLists
  GET /todo_lists
    works! (now write some real specs)

User
  add some examples to (or delete) /home/treehouse/projects/odot/spec/models/user_spec.rb (PENDING: No reason given)

Completing todo items
  is successful when marking a single item complete
  with completed items
    shows completed items as complete
    does not give the option to mark complete

Viewing todo items
  is successful with valid content
  displays an error with content less than 2 characters long
  displays an error with no content

TodoList
  should have many todo_items
  #has_complete_items?
    returns true with completed todo list items
    returns false with no completed todo list items
  #has_incomplete_items?
    returns true with incompleted todo list items
    returns false with no incomplete todo list items

todo_lists/index
  renders a list of todo_lists

TodoItem
  should belong to todo_list
  #completed?
    is false when completed_is blank
    returns true when completed_at is not empty

users/edit
  renders the edit user form

users/show
  renders attributes in <p>

todo_lists/show
  renders attributes in <p>

TodoListsController
  routing
    routes to #destroy
    routes to #show
    routes to #new
    routes to #create
    routes to #update
    routes to #index
    routes to #edit

TodoListsHelper
  add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/todo_lists_helper_spec.rb (PENDING: No reason given)

Pending:
  UsersHelper add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/users_helper_spec.rb
    # No reason given
    # ./spec/helpers/users_helper_spec.rb:14
  TodoItemsHelper add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/todo_items_helper_spec.rb
    # No reason given
    # ./spec/helpers/todo_items_helper_spec.rb:14
  todo_items/index.html.erb add some examples to (or delete) /home/treehouse/projects/odot/spec/views/todo_items/index.html.erb_spec.rb
    # No reason given
    # ./spec/views/todo_items/index.html.erb_spec.rb:4
  User add some examples to (or delete) /home/treehouse/projects/odot/spec/models/user_spec.rb
    # No reason given
    # ./spec/models/user_spec.rb:4
  TodoListsHelper add some examples to (or delete) /home/treehouse/projects/odot/spec/helpers/todo_lists_helper_spec.rb
    # No reason given
    # ./spec/helpers/todo_lists_helper_spec.rb:14

Failures:

  1) Viewing todo items displays the title of the todo list
     Failure/Error: within("h1") do
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching css "h1"
     # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

Deprecation Warnings:

--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from /home/treehouse/projects/odot/spec/helpers/todo_items_helper_spec.rb:14:in `block in <top (required)>'.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from /home/treehouse/projects/odot/spec/helpers/todo_lists_helper_spec.rb:14:in `block in <top (required)>'.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from /home/treehouse/projects/odot/spec/helpers/users_helper_spec.rb:14:in `block in <top (required)>'.

--------------------------------------------------------------------------------
Too many similar deprecation messages reported, disregarding further reports. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.

--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.

To keep the same skip semantics, change `pending` to `skip`.  Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.

Called from /home/treehouse/projects/odot/spec/views/todo_items/index.html.erb_spec.rb:4:in `block in <top (required)>'.

--------------------------------------------------------------------------------

`be_false` is deprecated. Use `be_falsey` (for Ruby's conditional semantics) or `be false` (for exact `== false` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_list_spec.rb:16:in `block (3 levels) in <top (required)>'.
`be_false` is deprecated. Use `be_falsey` (for Ruby's conditional semantics) or `be false` (for exact `== false` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_list_spec.rb:30:in `block (3 levels) in <top (required)>'.
`be_false` is deprecated. Use `be_falsey` (for Ruby's conditional semantics) or `be false` (for exact `== false` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_item_spec.rb:11:in `block (3 levels) in <top (required)>'.

`be_true` is deprecated. Use `be_truthy` (for Ruby's conditional semantics) or `be true` (for exact `== true` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_list_spec.rb:11:in `block (3 levels) in <top (required)>'.
`be_true` is deprecated. Use `be_truthy` (for Ruby's conditional semantics) or `be true` (for exact `== true` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_list_spec.rb:25:in `block (3 levels) in <top (required)>'.
`be_true` is deprecated. Use `be_truthy` (for Ruby's conditional semantics) or `be true` (for exact `== true` equality) instead. Called from /home/treehouse/projects/odot/spec/models/todo_item_spec.rb:16:in `block (3 levels) in <top (required)>'.

`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/todo_lists/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/users/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/todo_lists/edit.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
Too many uses of deprecated '`stub_model`'. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

19 deprecation warnings total

Finished in 12.12 seconds
89 examples, 1 failure, 5 pending

Failed examples:

rspec ./spec/features/todo_items/index_spec.rb:6 # Viewing todo items displays the title of the todo list

Randomized with seed 4873

/home/treehouse/.rbenv/versions/2.0.0-p353/bin/ruby -S rspec ./spec/controllers/todo_items_controller_spec.rb ./spec/controllers/todo_lists_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/features/todo_items/complete_spec.rb ./spec/features/todo_items/create_spec.rb ./spec/features/todo_items/delete_spec.rb ./spec/features/todo_items/edit_spec.rb ./spec/features/todo_items/index_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_spec.rb ./spec/helpers/todo_items_helper_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/helpers/users_helper_spec.rb ./spec/models/todo_item_spec.rb ./spec/models/todo_list_spec.rb ./spec/models/user_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/routing/users_routing_spec.rb ./spec/views/todo_items/index.html.erb_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb ./spec/views/users/edit.html.erb_spec.rb ./spec/views/users/new.html.erb_spec.rb ./spec/views/users/show.html.erb_spec.rb failed
treehouse:~/projects/odot (Start-of-User-Authentication-Course *) $ 

Looking at the page via localhost I'm thinking it's being caused from having two h1's on the page that aren't defined/separated well. One for the nav (why would they do this?...LOL.) and one for the title? But I'm so new at rails I'm having a hard time adding a class or something to the h1 in spec to differentiate.

<body>

  <div class="nav">
    <h1><a href="/">Odot</a></h1>
    <ul>
        <li><a href="/todo_lists">Todo Lists</a></li>
    </ul>
    <br class="clear" />
  </div>


<h1>Test</h1>

<h2>Test 2</h2>



<a href="/todo_lists/5/edit">Edit</a> |
<a href="/todo_lists">Back</a>


</body>
</html>
John Simoneau
John Simoneau
Courses Plus Student 8,105 Points

Not sure why my html isn't displaying correctly in the second paste above. I'll try it again...

<body>

  <div class="nav">
    <h1><a href="/">Odot</a></h1>
    <ul>
        <li><a href="/todo_lists">Todo Lists</a></li>
    </ul>
    <br class="clear" />
  </div>


<h1>Test</h1>

<h2>Test 2</h2>



<a href="/todo_lists/5/edit">Edit</a> |
<a href="/todo_lists">Back</a>


</body>
</html>