On 10/24/07, Feng Tien <pood.forums / gmail.com> wrote: > I've been learning Ruby the last couple weeks and trying to figure how > to Unit Test > > I wrote a method that outputs a few lines of text. > > How do I write an assertion so it tests if, say the last line printed is > equal to the expected? Lasts just say the program asks for 2 numbers, > and outputs all the number from the lowest to the highest. > > > I tried using: > > assert_equal '11' , fizzbang(10,100) > > but that does not work, because puts methods outputs are nil. > > how do you match puts? is there a different assertion you have to use? > > or is there no way to do this with Test::Unit assertion, will I have to > extract the text somehow from the method? How do I do that? > > Thanks! The idea about Unit Testing is, you do not write tests to test libraries, but you write tests to test your code. So, your idea of having assert_equal on puts is flawed from beginning. If you want to test how many numbers was in your output, you are probably better off saving that output in some variable and running asserts against the variable. While Unit Testing, its very important to understand, what you want to test? It comes with a little practise. Libraries like RSpec help in that. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org