Click here to Skip to main content
15,884,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have spent over an hour trying to figure out how to solve the error, but nothing works.

Here is the error message:


say_hello
  accepts an argument of a name and prints out Hello with that Name (FAILED - 1)
  defaults to Ruby Programmer when no name is passed in (FAILED - 2)

Failures:

  1) say_hello accepts an argument of a name and prints out Hello with that Name
     Failure/Error: expect($stdout).to receive(:puts).with("Hello Kent Beck!")

       (#<IO:<STDOUT>>).puts("Hello Kent Beck!")
           expected: 1 time with arguments: ("Hello Kent Beck!")
           received: 0 times
     # ./spec/say_hello_spec.rb:6:in `block (2 levels) in <top (required)>'

  2) say_hello defaults to Ruby Programmer when no name is passed in
     Failure/Error: expect($stdout).to receive(:puts).with("Hello Ruby Programmer!")

       (#<IO:<STDOUT>>).puts("Hello Ruby Programmer!")
           expected: 1 time with arguments: ("Hello Ruby Programmer!")
           received: 0 times
     # ./spec/say_hello_spec.rb:11:in `block (2 levels) in <top (required)>'

Finished in 0.01319 seconds (files took 0.19887 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/say_hello_spec.rb:5 # say_hello accepts an argument of a name and prints out Hello with that Name
rspec ./spec/say_hello_spec.rb:10 # say_hello defaults to Ruby Programmer when no name is passed in


What I have tried:

def say_hello (name = "Ruby Programming")
  "Hello, #{name}!"
end

say_hello ("Gabriela")



def say_hello (name = "Ruby Programming")
  puts "Hello, #{name}!"
end

say_hello ("Gabriela")
Posted

1 solution

I think it is because the testing software is configured to accept only a specific result, as you can see in the following code:
Failure/Error: expect($stdout).to receive(:puts).with("Hello Kent Beck!")
You can fix this by removing the extra comma that you placed in the code:
Python
def say_hello (name = "Ruby Programming")
  puts "Hello #{name}!"
end

say_hello ("Gabriela")
Now, run the code again.

It should pass, but if it fails again, try removing your call to the function, say_hello("Gabriella"), and run it again. Maybe the testing software is configured to accept only the specific response and nothing more than that.
 
Share this answer
 
v3
Comments
michellekadiehl 22-Jun-20 3:12am    
Hi Afzaal,

So I tried fixed the code and got the same response.

Here's the instructions I had to follow for my lab:

Objectives:

Build a method that can be called with an optional argument by defining that method with a default argument.

Instructions:

You will build a method called say_hello. This method should accept the argument of a person's name. It then should print "Hello " with the name followed by an exclamation point (don't forget that space after the "Hello"). For instance:

# I call on the method, say_hello, and give it the string "Gabriela"
say_hello("Gabriela")

# The method prints this text to the screen:
Hello Gabriela!

There is one more thing this method should do: if you call on this method and forget to give it the name of a person, it should just say, "Hello Ruby Programmer!". Use a default argument to accomplish this!

Steps:

1.Run learn to see where you stand.
2.You probably got two NoMethodErrors. This means the test was looking for a method called say_hello but couldn't find it.
3.Define the method in say_hello.rb
4.Run learn again. Are you getting a different error? If you haven't seen this error, guess what it's trying to tell you then Google it with the word "ruby".
5.Get all the tests to pass!
6.Once all of the tests are passing, use learn submit to submit your lab.
Afzaal Ahmad Zeeshan 22-Jun-20 10:57am    
Try removing the say_hello("Gabriela") part, maybe you are not required to call the function as the testing part will do that for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900