这是问题
更正代码,以便greet函数返回预期值 这是代码
class Person
def initialize(name)
@name = name
end
def greet(other_name)
"Hi #{other_name}, my name is #{name}"
end
end
这是我的解决方案
class Person
attr_reader :name, :other_name
def initialize(name)
@name = name
end
def greet(other_name)
puts " \"Hi #{other_name}, my name is #{@name}\" "
end
end
object = Person.new("Joe")
object.greet("Kate")
提供以下错误
`expect': Expected: "Hi Kate, my name is Joe", instead got: nil (Test::Error) from `assert_equals' from `
'
答案 0 :(得分:2)
puts
是一种返回nil
的方法,因此即使您看到正确的输出,测试也不会那样看。