dimanche 30 septembre 2018

How do I get the method and the string on the same line with a puts statement in Ruby?

The code below prints out the result that I want but the problem is that the tests are expecting a puts statement. This is the error message I get:

Failure/Error: expect($stdout).to receive(:puts).with("The line is currently: 1. Amanda 2. Annette 3. Ruchi 4. Jason 5. Logan 6. Spencer 7. Avi 8. Joe 9. Rachel 10. Lindsey")

   (#<IO:<STDOUT>>).puts("The line is currently: 1. Amanda 2. Annette 3. Ruchi 4. Jason 5. Logan 6. Spencer 7. Avi 8. Joe 9. Rachel 10. Lindsey")
       expected: 1 time with arguments: ("The line is currently: 1. Amanda 2. Annette 3. Ruchi 4. Jason 5. Logan 6. Spencer 7. Avi 8. Joe 9. Rachel 10. Lindsey")
       received: 0 times

How do I get the method and the string to display on the same line with a puts statement in Ruby?

Here's my code:

def line (katz_deli)

    if katz_deli.empty?  
       puts "The line is currently empty." 
    else
       print "The line is currently: "

       katz_deli.each_with_index{|name, index| 
       print "#{index + 1}. #{name}"
        }
    end

end

I've tried creating a variable and it doesn't print out the index only the array; I've tried using puts which just prints the array and index on the next line obviously so it brings up the error message.

Thanks so much for your help x

Aucun commentaire:

Enregistrer un commentaire