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 trial

Ruby

Vlad Filiucov
Vlad Filiucov
10,665 Points

Odot test do not pass

i exercise ago all test where passing. Now on deleting i got 6 errors. Stuck here for 4 hours. Done everything like in video and still got same errors. Can someone help me read them and track bug?

Failures:

1) Deleting todo list is successful when clicking the destroy link Failure/Error: expect(page).to_not have_content(todo_list.title) expected not to find text "Groceries" in "Listing todo_lists Title Description Groceries Grocery list Show Edit Destroy New Todo list" # ./spec/features/todo_lists/destroy_spec.rb:12:in `block (2 levels) in <top (required)>'

2) TodoListsController GET index assigns all todo_lists as @todo_lists Failure/Error: assigns(:todo_lists).should eq([todo_list])

   expected: [#<TodoList id: 2, title: "MyString", description: "My Description", created_at: "2015-03-09 12:30:03", updated_at: "2015-03-09 12:30:03">]
        got: #<ActiveRecord::Relation [#<TodoList id: 1, title: "Groceries", description: "Grocery list", created_at: "2015-03-09 09:17:58", updated_at: "2015-03-09 09:17:58">, #<TodoList id: 2, title: "MyString", description: "My Description", created_at: "2015-03-09 12:30:03", updated_at: "2015-03-09 12:30:03">]>

   (compared using ==)

   Diff:
   @@ -1,2 +1,3 @@
   -[#<TodoList id: 2, title: "MyString", description: "My Description", created_at: "2015-03-09 12:30:03", updated_at: "2015-03-09 12:30:03">]
   +[#<TodoList id: 1, title: "Groceries", description: "Grocery list", created_at: "2015-03-09 09:17:58", updated_at: "2015-03-09 09:17:58">,
   + #<TodoList id: 2, title: "MyString", description: "My Description", created_at: "2015-03-09 12:30:03", updated_at: "2015-03-09 12:30:03">]

 # ./spec/controllers/todo_lists_controller_spec.rb:37:in `block (3 levels) in <top (required)>'

3) Creating todo list Displays an error when the todo list has no title Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:25:in `block (2 levels) in <top (required)>'

4) Creating todo list Displays an error when the todo list has no Description Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:51:in `block (2 levels) in <top (required)>'

5) Creating todo list Displays an error when the todo list has a Description less than 3 characters Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:65:in `block (2 levels) in <top (required)>'

6) Creating todo list Displays an error when the todo list has a title less than 3 characters Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:39:in `block (2 levels) in <top (required)>'
Brandon Keene
Brandon Keene
7,217 Points

Could you post your code from the following two files, please? /spec/controllers/todo_lists_controller_spec.rb and /spec/features/todo_lists/create_spec.rb

Seeing those files may help us determine what's wrong.

11 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Vlad, I downloaded your code, deployed it locally and I don't get any errors in ./spec/features/todo_lists/create_spec.rb - everything passes and is green.

I used bundle exec rspec spec/features/todo_lists/create_spec.rb, then bin/rspec spec/features/todo_lists/create_spec.rb and in both cases all the tests pass properly.

I use Ruby 2.2.0, the terminal confirms that rspec v2.99.2 is used (rspec -v). Your models and controllers look fine. I don't know how to help you at this point. You could try downloading the project from github, doing bundle install, rake db:migrate and rake db:migrate RAILS_ENV=test and run rspec again on that code.

Vlad Filiucov
Vlad Filiucov
10,665 Points

The only thing that we modify in ./controller/todo_list_contoller_spec.rb is valid attributes. Here they are

describe TodoListsController do

# This should return the minimal set of attributes required to create a valid # TodoList. As you add validations to TodoList, be sure to # adjust the attributes here as well. let(:valid_attributes) { { "title" => "MyString", "description" => "My Description" } }

# This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # TodoListsController. Be sure to keep this updated too. let(:valid_session) { {} }

describe "GET index" do it "assigns all todo_lists as @todo_lists" do todo_list = TodoList.create! valid_attributes get :index, {}, valid_session assigns(:todo_lists).should eq([todo_list]) end end

create_spec.rb

require 'spec_helper'

describe "Creating todo list" do

def create_todo_list(options={})
    options[:title] ||="My todo list"
    options[:description] ||="This is my todo list."

    visit "/todo_lists"
    click_link "New Todo list"
    expect(page).to have_content("New todo_list")

    fill_in "Title", with: options[:title]
    fill_in "Description", with: options[:description]
    click_button "Create Todo list"
end


it "redirects to the todo list index page on success" do
    create_todo_list
    expect(page).to have_content("My todo list")
end

it "Displays an error when the todo list has no title" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: ""

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("This is what i am doing today")
end



it "Displays an error when the todo list has a title less than 3 characters" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "Yo"

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("This is what i am doing today")
end

    it "Displays an error when the todo list has no Description" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "grocery list", description: ""

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("Grocery")
end



it "Displays an error when the todo list has a Description less than 3 characters" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "grocery list", description: "Yo"

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("Yo")
end

end

Couple of tests don't pass but application works fine. Except error messages. I mean if we submit an empty todo item get a red flash table, but there is no reason written(like description can't be blank). Where are those messages stored?

Brandon Keene
Brandon Keene
7,217 Points

OK, change the following three things and run it again and see if it works:

1 At the very top of your /spec/features/todo_lists/create_spec.rb paste in the following:

require 'spec_helper'

describe "Creating todo lists" do

and then, at the very bottom, outside of everything else, write another

end

2 You have the following test (it is the second to the last in create_spec.rb) written as

    it "Displays an error when the todo list has no Description" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "grocery list", description: ""

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("Grocery") #<----THIS LINE
end

You'll see where I've added a comment pointing to the relevant line. Change ("Grocery") to ("grocery list").

3 In the test below that one (the final test in create_spec.rb) you have written the following:

it "Displays an error when the todo list has a Description less than 3 characters" do
    expect(TodoList.count).to eq(0)

    create_todo_list title: "grocery list", description: "Yo"

    expect(page).to have_content("error")
    expect(TodoList.count).to eq(0)

    visit "/todo_lists"
    expect(page).to_not have_content("Yo") #<----THIS LINE
end

Again, you'll see where I've added a comment pointing to the relevant line. Change ("Yo") to ("grocery list").

In both 2. and 3. I think what is happening is that you're passing have_content() a string to look for, but nothing in your test will generate that string. Based on my own files from the project, I believe have_content() needs to be passed the title, which the test is supposed to create, and you have set to "grocery list."

I can't promise that any of these will help, but they're what I would change if I were faced with the same errors. If they don't work, let us know and I or someone else might be able to take another crack at it. Hope this helps!

Vlad Filiucov
Vlad Filiucov
10,665 Points

I had that line with require spec helper. Modified expectation content but that didn't fix anything. I still run into the same error for all tests and i think the problem is not in the test but somewhere in controller or model. Because tests expect that nothing is saved and it actual isn't. When i enter invalid content nothing is saved and i get an error. But when i run test they say that something is saved. How?

Failures:

1) Creating todo lists Displays an error when the todo list has no Description Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:50:in `block (2 levels) in <top (required)>'

2) Creating todo lists Displays an error when the todo list has no title Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:24:in `block (2 levels) in <top (required)>'

3) Creating todo lists Displays an error when the todo list has a title less than 3 characters Failure/Error: expect(TodoList.count).to eq(0)

   expected: 0
        got: 1

   (compared using ==)
 # ./spec/features/todo_lists/create_spec.rb:38:in `block (2 levels) in <top (required)>'
Brandon Keene
Brandon Keene
7,217 Points

I'm afraid I don't have a better sense of what could be going on, but I'll tag Maciej Czuchnowski in on this. From what I've seen, there's a solid chance he may be able prove more helpful than I can!

Vlad Filiucov
Vlad Filiucov
10,665 Points

Thanks anyway for your time! I'l post here link on github.

https://github.com/VladFiliucov/odot

Vlad Filiucov
Vlad Filiucov
10,665 Points

i dropped DB then migrated it. Anyway when i run bin/rails spec i get 7 errors. And some fails seem completely illogic! like this one. In todo_list_spec.rb i have 4 times written todo_list.todo_item create. 3 times it passes and in last test i get

7) TodoList returns false with no incomplted todo list items Failure/Error: todo_list.todo_items.create(content: "Eggs", completed_at: 1.minute.ago) NameError: undefined local variable or method todo_list' for #<RSpec::Core::ExampleGroup::Nested_14:0x007f972ebb9af0> # ./spec/models/todo_list_spec.rb:30:inblock (2 levels) in <top (required)>'

how can it be? if 3 other test have same object in them. Why exactly this one is undefined?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, please give me the list of all the errors you get now.

Vlad Filiucov
Vlad Filiucov
10,665 Points

Failures:

1) Viewing todo items displays the title of the todo list Failure/Error: within("h1") do Capybara::Ambiguous: Ambiguous match, found 2 elements matching css "h1" # ./spec/features/todo_items/index_spec.rb:10:in `block (2 levels) in <top (required)>'

2) Viewing todo items displays item content when todo list has items Failure/Error: expect(page.all("ul.todo_items li").size).to eq(2)

   expected: 2
        got: 0

   (compared using ==)
 # ./spec/features/todo_items/index_spec.rb:26:in `block (2 levels) in <top (required)>'

3) todo_lists/index renders a list of todo_lists Failure/Error: assert_select "tr>td", :text => "Title".to_s, :count => 2 Minitest::Assertion: Expected exactly 2 elements matching "tr > td", found 0. Expected: 2 Actual: 0 # ./spec/views/todo_lists/index.html.erb_spec.rb:20:in `block (2 levels) in <top (required)>'

4) Adding todo items is successful with valid content Failure/Error: within("ul.todo_items") do Capybara::ElementNotFound: Unable to find css "ul.todo_items" # ./spec/features/todo_items/create_spec.rb:13:in `block (2 levels) in <top (required)>'

5) Adding todo items Displays an error with no content Failure/Error: expect(page).to have_content("Content can't be blank") expected to find text "Content can't be blank" in "odot Todo Lists There was a problem adding that todo list item. Grocery list - Add Todo List Item 2 errors prohibited this todo item from being saved: Content" # ./spec/features/todo_items/create_spec.rb:26:in `block (2 levels) in <top (required)>'

6) Adding todo items Displays an error with content less than 2 characters long Failure/Error: expect(page).to have_content("Content is to short") expected to find text "Content is to short" in "odot Todo Lists There was a problem adding that todo list item. Grocery list - Add Todo List Item 1 error prohibited this todo item from being saved: Content" # ./spec/features/todo_items/create_spec.rb:39:in `block (2 levels) in <top (required)>'

7) TodoList returns false with no incomplted todo list items Failure/Error: todo_list.todo_items.create(content: "Eggs", completed_at: 1.minute.ago) NameError: undefined local variable or method todo_list' for #<RSpec::Core::ExampleGroup::Nested_14:0x007fe1ddf68d50> # ./spec/models/todo_list_spec.rb:30:inblock (2 levels) in <top (required)>'

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, I think I'm getting the same errors, so I'll tinker with the code a bit and make a pull request on your github repo if that's OK (will be faster and more readable than publishing code snippets here).

Vlad Filiucov
Vlad Filiucov
10,665 Points

thanks. I just learn to code. I will see what you changed when i run a git diff command? I'm extremly curious what did i do wrong)

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I created the pull request. These are all the changes, some cosmetic, some actual code changes that were required: https://github.com/mczuchnowski/odot-1/commit/bb9be1c52f75296615a256ac0984bdedbce7469d

Vlad Filiucov
Vlad Filiucov
10,665 Points

Thats a lot of fixes! Thank you for your time and effort. I really appreciate it! I will now try to think every line changed by myself so i can max out of it. I wanted to ask: You removed almost everything form /spec/view directory. And i see lines that appeared in my errors there. I can't remember Jason doing anything in that folder. Anyway in video everything works. Does it have something to do with version of rails?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Apparently Jason has some configuration that prevents view specs form being generated when scaffolds are run. View tests are rarely used and when they are, they are not easy to do properly. Especially when you're just starting in Rails, so I removed these tests to prevent failures in places that are not covered by this course. If more files pop up there in the future, make sure you remove them as well.

Vlad Filiucov
Vlad Filiucov
10,665 Points

Thanks again Maciej! I guess most of my errors you fixed by changing |todo_list_items_path" to "todo_list_path(@todo_list)". Can you please tell me what is the difference between them? And can you insert link with fix errors into comment here so i can mark it as the best answer? I am pretty sure that someone will run into the same errors sooner or later) You posted it into comment to my reply so i can't mark it as the best answer(

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Paths are one of the concepts that you have to practice to start feeling it. I'm not sure what these previous path were in your code, but todo_list_path(@todo_list) is something that I took from rake routes command.