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 trialSophia Harrison
4,534 PointsNoMethodError: has_completed_items?; has_incomplete_items?
All four of my tests are failing, even though the code is exactly the same a Jason's (I copied and pasted it just to make sure). Any suggestions?
require 'spec_helper'
describe TodoList do
it { should have_many(:todo_items) }
describe "#has_complete_items?" do
let(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery list") }
it "returns true with completed todo list items" do
todo_list.todo_items.create(content: "Eggs", completed_at: 1.minute.ago)
expect(todo_list.has_completed_items?).to be_true
end
it "returns false with no completed todo list items" do
todo_list.todo_items.create(content: "Eggs")
expect(todo_list.has_completed_items?).to be_false
end
end
describe "#has_incomplete_items?" do
let(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery list") }
it "returns true with incompleted todo list items" do
todo_list.todo_items.create(content: "Eggs")
expect(todo_list.has_incomplete_items?).to be_true
end
it "returns false with no incomplete todo list items" do
todo_list.todo_items.create(content: "Eggs", completed_at: 1.minute.ago)
expect(todo_list.has_incomplete_items?).to be_false
end
end
end
class TodoList < ActiveRecord::Base
has_many :todo_items
validates :title, presence: true
validates :title, length: { minimum: 3 }
validates :description, presence: true
validates :description, length: { minimum: 5 }
def has_completed_items?
todo_items.complete.size > 0
end
def has_incomplete_items?
todo_items.incomplete.size > 0
end
end
2 Answers
kabir k
Courses Plus Student 18,036 PointsAlso, Inside the it
method, change both be_true
and be_false
to be true
and be false
respectively. It has been updated.
Sophia Harrison
4,534 Pointssupergirl630/teatree
Maciej Czuchnowski
36,441 PointsSophia, this project does not have has_complete_items? method at all in it and it does not have tests for it.
Sophia Harrison
4,534 PointsI forgot to push the most recent git updates over. Just did it. The files and tests are in app\views\todo_list\show.html.erb app\models\concerns\todo_list.rb spec\models\todo_list_spec.rb
Maciej Czuchnowski
36,441 PointsI pulled the newest version, your todo_list model still does not have these lines:
def has_completed_items?
todo_items.complete.size > 0
end
def has_incomplete_items?
todo_items.incomplete.size > 0
end
https://github.com/supergirl630/teatree/blob/master/app/models/todo_list.rb
When I added them, these errors were gone, but new ones appeared.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsCould you publish your project on GitHub and link it here? Then I could deploy it locally and find the problem.