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


Getting a failure in "displays item content the when a todo list has items", size is 1 instead of 2

Here's my test:

    it "displays item content when a todo list has items" do
        todo_list.todo_items.create(content: "Milk")
        todo_list.todo_items.create(content: "Eggs")


        expect(page.all("ul.todo_items li").size).to eq(2)

        within "ul.todo_items" do
            expect(page).to have_content("Milk")
            expect(page).to have_content("Eggs")

Here's the failure:

1) 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: 1

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

The line todo_list.todo_items.create(content: "Milk") doesn't get executed/isn't counted. Removed expect(page.all("ul.todo_items li").size).to eq(2) to see if it finds both items ("milk" and "eggs") - it does, so obviously it's created. Any ideas what's going on?

1 Answer

Found the culprit: typo in /todo_items/index.html.erb:

<ul class="todo_items"
  <% @todo_list.todo_items.each do |item| %>
  <li><%= item.content %></li>
  <% end %>

instead of

<ul class="todo_items">
  <% @todo_list.todo_items.each do |item| %>
  <li><%= item.content %></li>
  <% end %>