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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Editing Todo Lists

Receiving a Failure when running test

1) Editing todo lists updates a todo list successfully with correct information
     Failure/Error: within "#todo_list_#{todo_list.id}" do
     NameError:
       undefined local variable or method `todo_list' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000001b58550>
     # ./spec/features/todo_lists/edit_spec.rb:9:in `block (2 levels) in <top (required)>'

Finished in 0.03715 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/edit_spec.rb:4 # Editing todo lists updates a todo list successfully with correct information

Randomized with seed 45171

This is the error that I receive when I run the following code I can't seem to find where the error is on that line.

require 'spec_helper'

describe "Editing todo lists" do
    it "updates a todo list successfully with correct information" do
        todo_lists = TodoList.create(title: "Groceries", description: "Grocery List.")


        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do        # Here is where the error is and I can't see it.
            click_link "Edit"

        end

        fill_in "Title", with: "New title"
        fill_in "Description", with: "New description"
        click_button "Update Todo_list"


        expect(page).to have_content("Todo list was successfully updated")
        expect(todo_list.title).to eq("New title")
        expect(todo_list.description).to eq("New description")

  end

end

Thanks for any help you can give I am sure that I am missing something very simple here.

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

In line 5 you are creating the variable with plural name and your test expects a singular name.

We may be having a similar problem. I have been getting an error with my app as well. I have been comparing your 'edit.spec.rb' to mine and I think that I may have discovered my problem. We might have the same issue but with different portions of the app. The code for creating a title in mine is slightly different but here it is:

let!(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery List:")}

In my 'index.spec.rb code the create title code is:

let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }

Titles and descriptions are turned around in mine and 'list' is not captilized in the second snippet of code. This might be what is creating your problem.

I have not had a chance to check this out yet, but if I find something different I will let you know.

Bob