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

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")

        visit_todo_list(todo_list)

        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")
        end
    end

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 %>
</ul>

instead of

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