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

Tim Moreton
Tim Moreton
5,672 Points

Adding Todo List items Errors

I've run successful tests for the Todo list project up until the adding todo items sections where I keep getting different error messages below. The block of code it is referring to is below along with both error messages and a link to github


Adding todo items is successful with valid content (FAILED - 1)

Failures:

1) Adding todo items is successful with valid content Failure/Error: expect(page).to have_content("Added todo list item") expected to find text "Added todo list item" in "Grocery list Milk New Todo Item"

# ./spec/features/todo_items/create_spec.rb:18:in `block (2 levels) in <top (required)>'

Adding todo items is successful with valid content (FAILED - 1)

Failures:

1) Adding todo items is successful with valid content Failure/Error: Click_button "Save" NoMethodError: undefined method `Click_button' for #<RSpec::Core::ExampleGroup::Nested_1:0xba12bac8>

# ./spec/features/todo_items/create_spec.rb:17:in `block (2 levels) in <top (required)>'

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

def visit_todo_list(list)
    visit "/todo_lists"
    within "#todo_list_#{list.id}" do
        click_link "List Items"
    end
end

it "is successful with valid content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: "Milk"
    click_button "Save"
    expect(page).to have_content("Added todo list item")
    within("ul.todo_items") do
        expect(page).to have_content("Milk")
    end
end

end


https://github.com/tmoreton/todo.git

2 Answers

Alexander Batalov
Alexander Batalov
21,887 Points

I have cloned your app and found following typos:

  1. In your app/views/layouts/application.html.erb you forgot to close div (line:12)
<div class="alert flash <%= type %>"              <!--wrong-->
<div class="alert flash <%= type %>">             <!--correct-->
  1. In your spec/features/todo_items/create_spec.rb spotted typo (line:17)
Click_button "Save"     #wrong
click_button "Save"     #correct
  1. In your app/views/todo_items/index.html.erb you forgot to pass @todo_list to path (line:10)
<%= link_to "New Todo Item", new_todo_list_todo_item_path %>                      <!--wrong-->
<%= link_to "New Todo Item", new_todo_list_todo_item_path(@todo_list) %>         <!--correct-->

And a spec from spec/controllers/todo_items_controller_spec.rb not going to work anymore since we scoped todo items to todo lists, so feel free to remove it.

Hope it helps! Let me know if any help needed :) Cheers!

Tim Moreton
Tim Moreton
5,672 Points

This is awesome feedback, I had changed a few things since I posted on Github but I finally found the corrections you made and everything seems to be working now. Thanks so much for your help Alexander! I was starring at this same code for hours so this was a HUGE help.