user2420249
user2420249

Reputation: 248

assert_equal in Ruby have text error

i do test in ruby but get false message , but expected is true. i try give message '1' and in test give '1' but have error. What i do wrong ?
test code

assert_equal('Klient nr 1: Jan Kowalski, stan konta: 0 PLN', c1.to_s)

my code

def to_s()
    puts "Klient nr #{@p.nr}: #{@p.name} #{@p.surname}, stan konta: #{self.balance} PLN"
end

and have screen

error

Upvotes: 1

Views: 66

Answers (1)

Marty
Marty

Reputation: 7522

Your to_s method is printing the string, but it's not actually returning the string. Instead, it's returning nil, which is definitely not equal to your expected string.

Change it to return the string and you should be good:

def to_s()
    return "Klient nr #{@p.nr}: #{@p.name} #{@p.surname}, stan konta: #{self.balance} PLN"
end

Upvotes: 1

Related Questions