I am using the rails Draper gem and am in the process of testing my decorator methods now with Rails' built-in MiniTest framework.
I have a full_name method in my user_decorator.rb class, and want to write a test for this method. I also have first_name and last_name attributes on my User model.
My question is, what's the proper way to test that I get the correct output?
The method looks like this:
def full_name
first_name + ' ' + last_name
end
Which of the following ways is the correct way to test that I get the correct output from this method?
assert_equal 'Jourdan Bul-lalayao', @jourdan.full_name
or
assert_equal @jourdan.first_name + ' ' + @jourdan.last_name, @jourdan.full_name
To me, the first option seems correct; in the second option, it feels like I'm just writing the function again and testing the real function against that.
Though, I would love to have any thoughts, and perhaps any other suggestions that might be better!
Aucun commentaire:
Enregistrer un commentaire