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

I have a reference error in the Todo List project and I cannot figure it out.

Here is the message:

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

Failures:

  1) Viewing todo items displays the title of the todo list
     Failure/Error: expect(page).to have_content(todo_list.title)
       expected to find text "Grocery list" in "Listing todo_lists"
     # ./spec/features/todo_items/index_spec.rb:15:in `block (3 levels) in <top (required)>'
     # ./spec/features/todo_items/index_spec.rb:14:in `block (2 levels) in <top (required)>

Here is the code:

require 'spec_helper'

describe "Viewing todo items" do
    let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }

    before do
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do
            click_link "List Items"
        end
    end

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

    it "displays no items when the todo list is empty" do
        expect(page.all("ul.todo_items li").size).to eq(0)
    end
end

Thank you!

Please show us the code for the view responsible for this error.

Maciej,

Thank you for your quick response. I apologize for the length of time it has taken for me to get back with you. The code that is causing the errors to result is the following:

    within("h1") do
        expect(page).to have_content(todo_list.title)
    end

I am using Rails 4.1.7 if that helps.

Thank you!

Bob

I went back to my files and went through them one by one until I found the one that had the "Listing todo_lists" error. The following is the index.html.erb file that I think is looking for the Grocery list.

<h1>Listing todo_lists</h1>

<table>
  <thead>
    <tr>
      <th>Title</th>
      <th>Description</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @todo_lists.each do |todo_list| %>
      <tr id="<%= dom_id(todo_list)%>">
        <td><%= todo_list.title %></td>
        <td><%= todo_list.description %></td>
        <td>
        <a href="">List Items</a>
        <%= link_to 'Show', todo_list %>
        <%= link_to 'Edit', edit_todo_list_path(todo_list) %>
        <%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Todo list', new_todo_list_path %>

Again, thank you!

Bob

2 Answers

So, you are looking for content in h1:

within("h1")

But I don't see any h1 in your view.

Aside from the one that has the title of the page, which obviously does not contain the list title.

Maciej, thank you again. I apologize for not getting back with you sooner. I have had a lot happening besides this.

I went through my code module by module until I could find the reference to "Grocery list." I went through a lot of files and then I found the following difference between the code:

index_spec.rb has the following:

let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }

edit_spec.rb has this code:

let!(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery List:")}

The titles are different and the descriptions don't match each other either and I am guessing that this is the problem. Also, list is capitalized in the second description. I will try to change the titles and descriptions around to see if that will make it work. It seems to me that they are butting heads.

Thank you for your help!

Bob

Maciej,

I have gone back over the video more than once for this section of the video and I seem to be missing something. Somewhere in my code there is not a way for the h1 on the 'index.html.erb' to be updated, The changes that I tried did not make any difference. Do you think that I need something different in the line that the mentioned index page that actually links the title for the page?

Thank you again.

Bob

Maciej,

I went back in and changed the title of the page to Grocery list and it worked. The h1 test was included in the video and maybe I missed the part where the title was changed or a link was made to it. I have been having challenges with the videos bailing out on me while paused for more than a couple of minutes while I am typing and running my code. I know that it is longer than that sometimes, but it seems that for some reason whether it is my computer, something I have done inadvertently, or something with Treehouse, but I have had to restart many of the last videos more than once because this problem.

Thanks again for your great help!

Bob

I think you should remove the whole "within h1" form the spec - this way it will search the whole page. No idea why the spec has it at all. You can also put some h1 in the view, but then rspec will complain that it has more than one h1 tag on the page.

Robert,

Here are some ideas to try:

Replace let! with given!, which is Capybara's alias for let!

In your before block your problem may be in the within declaration...that #todo_list_#{todo.list.id} is pretty complex and your test might not be able to find that scope.

I would try to think of other ways you could get Capybara to follow your DOM where you wouldn't need that within line, perhaps find_link("List Items").click

http://www.rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders#find_link-instance_method

Let me know if that helps at all.

Nathan

Nathan,

Thank you for the information. I will give it a try in a few minutes. Things have been a little nuts the last few days. Again, I really appreciate the ideas that you mentioned.

Bob

Nathan,

I apologize for not getting back to you sooner on the code issue I have in my app for the todo_list. I tried your suggestions and they did not work. I may have found the problem with conflicting doce between two modules of the app. One has 'Groceries' as the list item and the other has 'Grocery List.'

I am hoping that this is the problem and not something else. I think that the problem is the connection between the screen and the keyboard.

Thanks again! I appreciate your help.

Bob