From: 7stud -- Date: 2007-10-24T16:01:27+09:00 Subject: Re: Unit Testing, how to use assert_equal for last printed line? Feng Tien wrote: > I've been learning Ruby the last couple weeks and trying to figure how > to Unit Test > Generally, you use assertions to test the return values of methods. Some people use "test driven design", which means they write the tests first, then they write code that complements the tests, i.e. code that is easily testable. So, for instance in your case, after writing your test, you might write a method that returns the values to be output, and then you would write some other code to output the values. Your unit test would test the return values from the method. However, you would not have any idea whether the code that outputs the values does so in the desired format. In my limited experience with unit testing, you can't easily unit test methods that gather user input or methods that output info to the user. For instance, if a method prompts the user for info, how can you unit test that method without actually entering input by hand. If you think about it for a little awhile, the solution involves replacing your data gathering method with a method that just returns lots of different values. There are theories about how to do that in the best way, and they use things called 'mock objects', which you can google. -- Posted via http://www.ruby-forum.com/.