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 trialivan quevedo
4,477 PointsIm having many errors, on the viewing todo items part 2
I get different errors after running the test
1) Viewing todo items displays the title of the todo list
Failure/Error: click_link "List Items"
ActionView::Template::Error:
undefined method todo_items' for #<TodoList:0x007fcb3f35ec08>
# ./app/views/todo_items/index.html.erb:5:in
app_views_todo_items_index_html_erb__3528535529875335308_70255457779520'
# ./spec/features/todo_items/index_spec.rb:9:in block in visit_todo_list'
# ./spec/features/todo_items/index_spec.rb:8:in
visit_todo_list'
# ./spec/features/todo_items/index_spec.rb:14:in `block (2 levels) in <top (required)>'
2) Viewing todo items displays item content when a todo list has items
Failure/Error: todo_list.todo_items.create(content: "Milk")
NoMethodError:
undefined method todo_items' for #<TodoList:0x007fcb3f3241e8>
# ./spec/features/todo_items/index_spec.rb:26:in
block (2 levels) in <top (required)>'
3) Viewing todo items displays no items when a todo list is empty
Failure/Error: click_link "List Items"
ActionView::Template::Error:
undefined method todo_items' for #<TodoList:0x007fcb3f2a42e0>
# ./app/views/todo_items/index.html.erb:5:in
app_views_todo_items_index_html_erb__3528535529875335308_70255457779520'
# ./spec/features/todo_items/index_spec.rb:9:in block in visit_todo_list'
# ./spec/features/todo_items/index_spec.rb:8:in
visit_todo_list'
# ./spec/features/todo_items/index_spec.rb:21:in `block (2 levels) in <top (required)>'
My Code is
todo_items_controller.rb
class TodoItemsController < ApplicationController def index @todo_list = TodoList.find(params[:todo_list_id]) end end
index.html.erb
class TodoItemsController < ApplicationController def index @todo_list = TodoList.find(params[:todo_list_id]) end end
index_spec.rb
require 'spec_helper'
describe "Viewing 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 "displays the title of the todo list" do visit_todo_list(todo_list) within("h1") do expect(page).to have_content(todo_list.title) end end
it "displays no items when a todo list is empty" do visit_todo_list(todo_list) expect(page.all("ul.todo_items li").size).to eq(0) end
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 end
1 Answer
J Scott Erickson
11,883 PointsI had a similar issue when I pulled down some of their code and changed the html.erb file for viewing todo list items without thinking about how it would affect my testing. You need to update your testing (likely) to the new layout. Which is in table format rather than in an unordered list. Try doing it without pulling their spec files, Its good practice.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 Pointsivan quevedo was the answer below helpful? If so, please indicate that by selecting it as Best Answer. If not, please elaborate more so that we could help you further.