makersacademy / problem-solving

For problem-solving during the PreCourse
6 stars 2 forks source link

Chapter 10: Question 1 #150

Closed NadiaAiraf closed 6 years ago

NadiaAiraf commented 6 years ago

Hey gang,

I'm having some issues getting the chapter 10 question to pass the rspec checker. Specifically when the rspec checker checks the print method it's puts'ing the Todo object and not the string expected. What's weird is that when I run this on my own I'm getting the expected results.

So this is the code image

It's failing the rspec on 2 examples where it's trying to use the print method in the TodoList class. The errors for one of those is as follows: image So this looks like it's outputting the objects created in the Todo class rather than the @ job variable and I have absolutely no idea why it's doing that.

What's making me scratch my head most is that when I run the file with some commands it seems to be working absolutely fine. So when I create a new TodoList instance and call the methods in it using the below: image

I'm getting the output that I'm expecting in the command line: image

afaraone commented 6 years ago

This might be why but it's a bit tricky for me to explain. I think the TodoList class is meant to accept Todo objects that have already been made. In line 42 you are creating a new Todo object.

Here is an example of what happens when you make a Todo object of a Todo object. I did this in irb. The lines after > is my input, and the lines after => is the output.

>   paper = Todo.new("get the paper")
=> #<Todo:0x005568eaec5ad8 @text="get the paper"> 
> paper.text
=> "get the paper" 
> paper2 = Todo.new(paper)
=> #<Todo:0x005568eaeb61a0 @text=#<Todo:0x005568eaec5ad8 @text="get the paper">> 
> paper2.text
=> #<Todo:0x005568eaec5ad8 @text="get the paper"> 
NadiaAiraf commented 6 years ago

Thanks Andres, you're right I was working under the assumption it should be taking a string as the parameter for the TodoList.add method whereas it was meant to be taking an object. I imagine that's why the rspec was outputting the hexidecimal.

It worked beautifully once I took out the part that created a new Todo object.