At the part of the third video (Writing Unit Tests) where Josh Clayton adds the scenario for testing completed todos and adds all the relevant code and runs the rspec on that code, it works for him but won’t work for me.
This issue is only partly resolved. When slightly refactoring the code in the integration/manage_todos file, I get a failure where I shouldn’t. If there’s a typo in the code, I am unable to see it. Any help at all would really be appreciated.
This is just a guess, but it looks like in line 3 of your index.html.erb, the ‘completed’ string needs to start with a space. As it is, that line is giving list elements that are completed one css class called todocomplete
instead two separate classes, one called todo
and one called complete
.
I might be wrong. so let me know if that doesn’t work.
I caught that after I went over my code for the 7th time and fixed it. However, during the refactoring part, I still get the same error. I should not get that error because I merely passed description to a method. Yet, I get an error saying that the problem is in lines 23, 27 and 49 of my code when I am not seeing what is wrong with the code.
require ‘spec_helper’
feature ‘Manage todos’ do
scenario ‘create new todo’ do
sign_in
create_todo_with_description 'Read three chapters of RSpec book'
user_sees_todo_item 'Read three chapters of RSpec book'
# RSpec deletes all the todos from the database
end
scenario ‘view only my todos’ do
# todo = Todo.where(description: ‘Read three chapters of RSpec book’).first
# expect(todo).to be_nil
sign_in
create(:todo, description: 'Buy coffee cream', owner_email: 'not_me@example.com')
user_does_not_see_todo_item 'Buy coffee cream'
end
scenario ‘denote completed todos’ do
sign_in
create_todo_with_description 'Buy coffee cream'
user_sees_completed_todo_item 'Buy coffee cream'
end
def complete_todo(description)
within “li.todo:contains(‘#{description}’)” do
click_link ‘Complete’
end
end
def create_todo_with_description(description)
click_link ‘Add new todo’
fill_in ‘Description’, with: description
click_button ‘Create todo’
end
def user_sees_todo_item(description)
expect(page).to have_css ‘li.todo’, text: description
end
def user_sees_completed_todo_item(description)
expect(page).to have_css ‘li.todo.completed’, text: description
end
def user_does_not_see_todo_item(description)
expect(page).not_to have_css ‘li.todo’, text: description
end
The following def block was moved into a module
to keep our features nice and slim.
The logic for signing in is in a module
that can be managed separately, so if the logic for
signing in changes, it’s all contained in the
SignInHelpers module under spec/support.
def sign_in
visit root_path
fill_in ‘Email address’, with: ‘person@email.com’
click_button ‘Sign In’
end
end
➜ todos git:(master) ✗ rspec spec/integration/manage_todos_spec.rb
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.0
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
…F
Failures:
- Manage todos denote completed todos
Failure/Error: expect(page).to have_css ‘li.todo.completed’, text: description
expected css “li.todo.completed” with text “Buy coffee cream” to return something./spec/integration/manage_todos_spec.rb:49:in `user_sees_completed_todo_item’
./spec/integration/manage_todos_spec.rb:28:in `block (2 levels) in <top (required)>’
Finished in 0.31083 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/integration/manage_todos_spec.rb:23 # Manage todos denote completed todos
Randomized with seed 48802
➜ todos git:(master) ✗