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

Generating errors in the todo_items section of the Rails todo list lesson

Hello,

I am getting errors when running the first test cases for the todo_items section of the Rails todo list lesson.

I should get one pass, one fail.
Instead I get two fails, neither of which are what the instructor suggests I should get.

I have investigated this off and on for about a week. Silver lining is this encouraged me to learn about git revert --hard; but even after starting from scratch again I error out at the same step. Clearly I have an anti-pattern pretty well ingrained, and need your help trying to break it.

Inline below are

  • the error text
  • index.html.erb from todo_items
  • the TodoItems Controller
  • index_spec.rb from todo_items

Thanks in advance, Greg

The error text

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

Failures:

  1) Viewing todo items displays the title of the todo list
     Failure/Error: click_link "List Items"
     ArgumentError:
       wrong number of arguments (1 for 0)
     # ./app/controllers/todo_items_controller.rb:3:in `index'
     # ./spec/features/todo_items/index_spec.rb:9:in `block (3 levels) in <top (required)>'
     # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

  2) Viewing todo items displays no items when a todo list is empty
     Failure/Error: click_link "List Items"
     ArgumentError:
       wrong number of arguments (1 for 0)
     # ./app/controllers/todo_items_controller.rb:3:in `index'
     # ./spec/features/todo_items/index_spec.rb:9:in `block (3 levels) in <top (required)>'
     # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

Apparently triple-back-tick html doesn't display as I thought it might. The h1-tag with the @todo_list.title is the interesting bit.

The index.html.erb

<h1><%= @todo_list.title %></h1> <p>Find me in app/views/todo_items/index.html.erb</p>

The Controller

class TodoItemsController < ApplicationController
  def index
    @todo_list = TodoList.find(params [:todo_list_id])
  end
end

The index_spec.rb

require 'spec_helper'

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

    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 a todo list is empty" do

        expect(page).to have_content("TodoItems#index")
    end
end 

2 Answers

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

In your controller, you have a space after params, so Ruby thinks you're calling the params method with an argument of [:todo_list_id]. That's the NoMethodError you're seeing in both test cases.

Woot! That was it.

Thanks a lot for your keen eyes where I had become snow blind.

Amy Kang
Amy Kang
17,188 Points

Try removing the within "#todo_list_#{todo_list.id}" do block and just leave click_link "List Items" then run the test again. If that works it means the problem is with your within block.

Got the same error for both test cases again. I will take a look at what else I might comment out. Thanks for the suggestion; I will try trimming a couple other things out and see what happens. :-)