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

Nelly Nelly
Nelly Nelly
7,134 Points

todo_list_controller_spec.rb issues....

Hi everybody , Hi Steve Hunter ,

i've downloaded the file from Jason's project, I don't know why I didnt have it... Well, lets start step by step maybe... If needed here is my git repo https://github.com/knopfler81/odot/tree/user_auth (updated with the current issue)

todo_list_controller_spec.rb

describe "GET index" do
    it "assigns all todo_lists as @todo_lists" do
      todo_list = TodoList.create! valid_attributes
      controller.stub(:require_user).and_return(true)
      get :index, {}, valid_session
      assigns(:todo_lists).should eq([todo_list])
    end
 end
I had depreciations errors and I found out on google that the syntax has changed (again lol) and now it's better to write:
  allow(controller).to receive(:require_user).and_return(true)

instead of

controller.stub(:require_user).and_return(true)

BUT

when I run rspec spec/controller/todo_lists_controller_spec.rb:15 ( it is on line 15 ;) )

I have this horrible thing:

TodoListsController
  GET index
    assigns all todo_lists as @todo_lists (FAILED - 1)

Failures:

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

       expected: [#<TodoList id: 6, title: "MyString", description: "My Description", created_at: "2016-08-08 19:43:15", updated_at: "2016-08-08 19:43:15">]
            got: #<ActiveRecord::Relation [#<TodoList id: 1, title: "MyString", description: "My Description", created...scription: "My Description", created_at: "2016-08-08 19:43:15", updated_at: "2016-08-08 19:43:15">]>

       (compared using ==)

       Diff:
       @@ -1,2 +1,37 @@
       -[#<TodoList id: 6, title: "MyString", description: "My Description", created_at: "2016-08-08 19:43:15", updated_at: "2016-08-08 19:43:15">]
       +[#<TodoList:0x007fc77886c3f0
       +  id: 1,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 18:29:32 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 18:29:32 UTC +00:00>,
       + #<TodoList:0x007fc77886c008
       +  id: 2,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 18:33:43 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 18:33:43 UTC +00:00>,
       + #<TodoList:0x007fc77885fe70
       +  id: 3,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 18:35:07 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 18:35:07 UTC +00:00>,
       + #<TodoList:0x007fc77885fba0
       +  id: 4,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 18:37:16 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 18:37:16 UTC +00:00>,
       + #<TodoList:0x007fc77885f718
       +  id: 5,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 18:38:07 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 18:38:07 UTC +00:00>,
       + #<TodoList:0x007fc77885f3a8
       +  id: 6,
       +  title: "MyString",
       +  description: "My Description",
       +  created_at: Mon, 08 Aug 2016 19:43:15 UTC +00:00,
       +  updated_at: Mon, 08 Aug 2016 19:43:15 UTC +00:00>]

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

Au secours

Au secours!

Yes, you've compared a relation to an instance. See?:

expected: [#<TodoList id: 6, title: "MyString", description: "My Description", created_at: "2016-08-08 19:43:15", updated_at: "2016-08-08 19:43:15">]
            got: #<ActiveRecord::Relation [#<TodoList id: 1, title: "MyString", description: "My Description", created...scription: "My Description", created_at: "2016-08-08 19:43:15", updated_at: "2016-08-08 19:43:15">]>

That's also compared the wrong id.

Downloading projects mid-Rails is a massive chore - it takes longer fixing stuff than writing it from scratch. But I don't think we're there with this. Here, your test expected to see a Todo list with an id of 6 a title of "MyString", a description of "My Description" etc.

It didn't find that. It got a Relation with a wrong id but correct strings. So you're not far away here.

Do you understand why I'm explaining the errors like that? Does that help move towards a solution?

Steve.

1 Answer

Nelly Nelly
Nelly Nelly
7,134 Points

Hi again Steve Hunter,

Actually when I said that I've downladed from Jason, I mean I only copied the two single files I was missing. todo_lists_controller_spec.rb and todo_list_items_controller_spec.rb

Hummmm and I don't know why but I didn't change anything in the code. BUT your reflexion made me think to an old case....where I spend hours finding the solution.... and that was... the same. So, I've deleted my development.sqlite3 and test.sqlite3 files... ran rake db:migrate, rake db:test:prepare, rake db:migrate RAILS_ENV=test

and now it's green :)

I will sleep a bit now and back into the code tomorrow :) Thanks again !