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 trialSuleiman Leadbitter
15,805 Pointshas_incomplete_items? rspec failing
I'm hitting a wall again so close to the end. I'm getting an error when testing the code.
This is my error in terminal rspec
Failures:
1) TodoList#has_incomplete_items? returns true with incompleted todo list items
Failure/Error: expect(todo_list.has_incompleted_items?).to be_true
NoMethodError:
undefined method `has_incompleted_items?' for #<TodoList:0x007f89b1afbd28>
# ./spec/models/todo_list_spec.rb:25:in `block (3 levels) in <top (required)>'
2) TodoList#has_incomplete_items? returns false with no incompleted todo list items
Failure/Error: expect(todo_list.has_incompleted_items?).to be_false
NoMethodError:
undefined method `has_incompleted_items?' for #<TodoList:0x007f89b1a3bd20>
# ./spec/models/todo_list_spec.rb:30:in `block (3 levels) in <top (required)>'
Deprecation Warnings:
`be_false` is deprecated. Use `be_falsey` (for Ruby's conditional semantics) or `be false` (for exact `== false` equality) instead. Called from /Users/Suleiman/Sites/education/odot/spec/models/todo_list_spec.rb:16:in `block (3 levels) in <top (required)>'.
`be_true` is deprecated. Use `be_truthy` (for Ruby's conditional semantics) or `be true` (for exact `== true` equality) instead. Called from /Users/Suleiman/Sites/education/odot/spec/models/todo_list_spec.rb:11:in `block (3 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.14757 seconds
5 examples, 2 failures
Failed examples:
rspec ./spec/models/todo_list_spec.rb:23 # TodoList#has_incomplete_items? returns true with incompleted todo list items
rspec ./spec/models/todo_list_spec.rb:28 # TodoList#has_incomplete_items? returns false with no incompleted todo list items
Randomized with seed 28072
I'm checking the code that it is suggesting but everything seems legit as far as I can tell.
This is my todo_list.rb
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
And this is my todo_list_spec.rb
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_incompleted_items?).to be_true
end
it "returns false with no incompleted todo list items" do
todo_list.todo_items.create(content: "Eggs", completed_at: 1.minute.ago)
expect(todo_list.has_incompleted_items?).to be_false
end
end
end
Any help so close to to the finish line would be so great, many thanks.
This is a link to the whole project on Github if that helps out at all - Github Treehouse Odot Project
Sul
2 Answers
Suleiman Leadbitter
15,805 PointsOK I seem to have figured it out.
It was the lines in todo_list_spec.rb
expect(todo_list.has_incompleted_items?).to be_true
Should be:
expect(todo_list.has_incomplete_items?).to be_true
Dropping the d :P
Angel Israel Gallegos Espinoza
3,096 PointsIf you are using the latest gems, you also have to change some syntaxis
.to be true
.to be false
instead of
.to be_true
.to be_false
Suleiman Leadbitter
15,805 PointsThanks! Good to know in the future.