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 trialJon Avila
Front End Web Development Techdegree Graduate 35,342 PointsRspec error, "undefined local variable or method `todo_list'", while writing edit_spec.rb for rails track. Please help.
I am working through the todo list course in the rails track, and got stuck, I keep getting this error. The instructor goes very fast and jumps around sometimes with the copying and pasting, so I'm surprised I haven't gotten lost sooner. lol I swear I have everything copied down exactly as he typed it, but I'm getting an error, so I'm sure there is a typo I'm not seeing. I'm sick of figuratively banging my head against my keyboard, so here I am reaching out. This is the code,
require 'spec_helper'
describe "Editing todo lists" do
def update_todo_list(options={})
options[:title] ||= "My todo list"
options[:description] ||= "This is my todo list."
todo_list = options[:todo_list]
visit "/todo_lists"
within "#todo_list_#{todo_list.id}" do
click_link "Edit"
end
fill_in "Title", with: options[:title]
fill_in "Description", with: options[:description]
click_button "Update Todo list"
end
it "updates a todo list succesfully with correct information" do
update_todo_list title: "New title",
description: "New description",
todo_list: todo_list
todo_list.reload
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
and this is the error,
Failures:
1) Editing todo lists updates a todo list succesfully with correct information
Failure/Error: todo_list:todo_list
NameError:
undefined local variable or method `todo_list' for #<RSpec::Core::ExampleGroup::Nested_1:0x000000052c99f8>
# ./spec/features/todo_list/edit_spec.rb:25:in `block (2 levels) in <top (required)>'
Please help me. Thank you.
Clair Griffiths
10,158 PointsClair Griffiths
10,158 PointsHi Jon
I think you may have missed a line in your test that creates the first todo list.
In the tutorial, right after
describe "Editing todo lists" do
there is the line
let!(:todo_list) {TodoList.create(title: "Groceries", description: "Grocery list")}
I tried adding this into your example and it made the test pass