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 PointsCapybara::ElementNotFound when doing rspec test for deletion
Code:
require 'spec_helper'
describe "Deleting todo lists" do
let!(:todo_list) {TodoList.create(title: "Groceries", description: "Grocery list.")}
let!(:todo_list) {TodoList.create(title: "", description: "")}
it "is successful when clicking the destroy link" do
visit "/todo_lists"
within "#todo_list_#{todo_list.id}" do
click_link "Destroy"
end
expect(page).to_not have_content(todo_list.title)
expect(TodoList.count).to eq(0)
end
end
Error:
treehouse:~/projects/odot (master) $ bin/rspec spec/features/todo_lists/destroy_spec.rb F
Failures:
1) Deleting todo lists is successful when clicking the destroy link Failure/Error: within "#todo_list_#{todo_list.id}" do Capybara::ElementNotFound: Unable to find css "#todo_list_" # ./spec/features/todo_lists/destroy_spec.rb:10:in `block (2 levels) in <top (required)>'
Finished in 0.3996 seconds 1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_lists/destroy_spec.rb:7 # Deleting todo lists is successful when clicking the destroy link
Randomized with seed 20493
treehouse:~/projects/odot (master) $
3 Answers
Maciej Czuchnowski
36,441 PointsHmmm...why this line? It seems to be creating an empty list that should be rejected by the validation. Try removing it.
let!(:todo_list) {TodoList.create(title: "", description: "")}
Jason Seifer
Treehouse Guest TeacherHey Richard Duffy it seems like you have to creations of the todo_list with the let!
statement. Try removing the second one and your test should pass.
Richard Duffy
16,488 PointsThanks!