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 trialRichard Duffy
16,488 PointsError!
Hello I keep getting this error:
treehouse:~/projects/odot (master *) $ bin/rspec spec/features/todo_lists/edit_spec.rb
F
Failures:
1) Editing todo lists updates a todo list successfully with correct information
Failure/Error: update_todo_list todo_list: todo_list,
NameError:
undefined local variable or method `todo_list' for #<RSpec::Core::ExampleGroup::Nested_1:0xb919adfc>
# ./spec/features/todo_lists/edit_spec.rb:22:in `block (2 levels) in <top (required)>'
Deprecation Warnings:
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
now yield the example as a block argument, and that is the recommended
way to access the current example from those contexts.
- The current example is now exposed via `RSpec.current_example`,
which is accessible from any context.
- If you can't update the code at this call site (e.g. because it is in
an extension gem), you can use this snippet to continue making this
method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
c.expose_current_running_example_as :example
end
(Called from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
now yield the example as a block argument, and that is the recommended
way to access the current example from those contexts.
- The current example is now exposed via `RSpec.current_example`,
which is accessible from any context.
- If you can't update the code at this call site (e.g. because it is in
an extension gem), you can use this snippet to continue making this
method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
c.expose_current_running_example_as :example
end
(Called from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
2 deprecation warnings total
Finished in 0.00355 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/edit_spec.rb:21 # Editing todo lists updates a todo list successfully with correct information
Randomized with seed 51884
treehouse:~/projects/odot (master *) $
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 successfully with correct information" do
todo_list = TodoList.create(title: "Groceries", description: "Grocery list.")
update_todo_list todo_list: todo_list,
title: "New title",
description: "New description"
todo_list.reload
expect(page).to have_content("Todo list was successfully updated")
expect(todo_list.title). eq("New title")
expect(todo_list.description).to eq("New description")
end
end
3 Answers
thomascawthorn
22,986 PointsRegarding the depreciation warnings this post might help you out.
maybe this line:
expect(todo_list.title). eq("New title")
should be
expect(todo_list.title).to eq("New title")
Cristian Daniel Marquez Barrios
8,900 PointsI got the same error for this code:
require 'spec_helper'
describe "Creating todo lists" do
it "redirects to the todo list index page on success" do
visit "/todo_lists"
click_link "New Todo list"
expect(page).to have_content("New todo_list")
fill_in "Title", with: "My todo list"
fill_in "Description", with: "This is what I'm doing today"
click_button "Create Todo list"
expect(page).to have_content("My todo list")
end
#Title
it "displays an error when the todo list has no title" do
expect(TodoList.count).to eq(0)
visit "/todo_lists"
click_link "New Todo list"
expect(page).to have_content("New todo_list")
fill_in "Title", with: ""
fill_in "Description", with: "This is what I'm doing today."
click_button "Create Todo list"
expect(page).to have_content("error")
expect(TodoList.count).to eq(0)
visit "todo_lists"
expect(page).to_not have_content("This is what I'm doing today.")
end
it "displays an error when the todo list has a title less than 3 characters" do
expect(TodoList.count).to eq(0)
visit "/todo_lists"
click_link "New Todo list"
expect(page).to have_content("New todo_list")
fill_in "Title", with: "Hi"
fill_in "Description", with: "This is what I'm doing today."
click_button "Create Todo list"
expect(page).to have_content("error")
expect(TodoList.count).to eq(0)
visit "todo_lists"
expect(page).to_not have_content("This is what I'm doing today.")
end
#Description
it "displays an error when the todo list has no Description" do
expect(TodoList.count).to eq(0)
visit "/todo_lists"
click_link "New Todo list"
expect(page).to have_content("New todo_list")
fill_in "Title", with: "Hola"
fill_in "Description", with: ""
click_button "Create Todo list"
expect(page).to have_content("error")
expect(TodoList.count).to eq(0)
visit "todo_lists"
expect(page).to_not have_content("Hola")
end
it "displays an error when the todo list has a title less than 3 characters" do
expect(TodoList.count).to eq(0)
visit "/todo_lists"
click_link "New Todo list"
expect(page).to have_content("New todo_list")
fill_in "Title", with: "Hola"
fill_in "Description", with: "This is what I'm doing today."
click_button "Create Todo list"
expect(page).to have_content("error")
expect(TodoList.count).to eq(0)
visit "todo_lists"
expect(page).to_not have_content("This is what I'm doing today.")
end
end
Richard Duffy
16,488 PointsThank you so much, it takes another person to sometimes see an error, thank you once again!