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 trialLandall Proctor
6,876 PointsUndefined method "dom_id_for"
I'm getting a failure message of undefined method for "dom_id_for" when trying to run the rspec test on complete_spec.rb. I don't get the failure message that is solved in the video.
The error is on line 10 which follows the exact code written in the video. My code is here:
require 'spec_helper'
describe "Completing todo items" do
let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries") }
let!(:todo_item) { todo_list.todo_items.create(content: "Milk") }
it "is successful when marking a single item complete" do
expect(todo_item.completed_at).to be_nil
visit_todo_list todo_list
within dom_id_for(todo_item) do
click_link "Mark Complete"
end
todo_item.reload
expect(todo_item.completed_at).to_not be_nil
end
end
Any help would be greatly appreciated. Thanks.
4 Answers
Landall Proctor
6,876 PointsSolved it.
I forget that upon creating the additional rails_dom_id_helper.rb file that I also had to include that in the spec_helper under the Rspec.configure like we did with the todo_list_helpers.rb file.
I'm pretty sure I didn't just miss the entire creation of a file and inclusion in that page, but it solves the problem so I'm not to worried about it.
Thanks for the help guys! It was really appreciated and pointed me to try a few additional steps to solve it.
Maciej Czuchnowski
36,441 PointsDid you define dom_id_for
anywhere in your code?
Landall Proctor
6,876 PointsI realize that's probably the issue. I just downloaded the teacher files and opened everything in a different sublime window. Searching for "dom_id_for" I found a file that we have not created yet:
rails_dom_id_helper.rb which is located in: spec/support folder
It appears to be defined there.
My search also found the same call to that method in the todo_list_helpers.rb in the same support folder. However, that differs from my code that I wrote from the video.
My original code:
module TodoListHelpers
def visit_todo_list(list)
visit "/todo_lists"
within "#todo_list_#{list.id}" do
click_link "List Items"
end
end
end
Code in the teacher file:
module TodoListHelpers
def visit_todo_list(list)
visit "/todo_lists"
within dom_id_for(list) do
click_link "List Items"
end
end
end
Creating the new file and copy/pasting the code did not fix my failure nor did changing the code in the todo_list_helpers.rb file, when I ran the test again.
Taking those steps feels a bit like cheating, but I feel like I'm running out of ideas on how to solve this.
Thanks for any additional ideas you might have.
Steve Hunter
57,712 PointsI think you have some brackets missing in the line before the one you mention:
it "is successful when marking a single item complete" do
expect(todo_item.completed_at).to be_nil
visit_todo_list(todo_list)
within dom_id_for(todo_item) do
click_link "Mark complete"
end
todo_item.reload
expect(todo_item.completed_at).to_not be_nil
end
Your code doesn't have (todo_list)
in parentheses.
Hope that helps!
Steve.
Landall Proctor
6,876 PointsJust tried that. Same failure.
Jason's (and others who have asked about other failure messages further down the code, seemingly passing this one) code doesn't have parentheses around that todo_list either.
I've ran rake db:migrate and rak db:migrate RAILS_ENV=test more times that probably necessary as it seemed like maybe it wasn't updating something in the schema.rb file. But that didn't do anything either.
Any other ideas? Thanks.
Steve Hunter
57,712 PointsCan you share your Github repo - I'll see if I can pull the code down and try it here in an attempt to track the error down.
Cheers,
Steve.