Hi Eric,
I'd do this with a mock object. With Mocha I'd do something like this:

myFoo.expects(:puts).with("bar")

The idea is that you don't really want to capture the output (you know
puts works) you just want to make sure it's called properly.

You may need to define a fake puts method in Foo to make this work. So
in your test:

class Foo
  def puts(*args)
  end
end

class TestCase...
end

On 9/8/06, Eric Boucher <devlists-ruby-talk / devlists.com> wrote:
> Hi,
>
> I want to be able to unit/test an output with the method 'puts'. Here's
> a small example of what I'm trying to achieve:
>
> #-------8<--------
> class Foo
>   def output
>     puts "bar"
>   end
> end
> #-------8<--------
>
> ...and in my test
>
> #-------8<--------
> require 'unit/test'
> ...
> def test_output
>    myFoo = Foo.new
>    assert_equal("bar", myFoo.output)
> end
> #-------8<--------
>
> The problem is that the 'puts' method returns nil and I don't know how
> to catch the output.
>
> Thanks in advance.
> --
> Posted with http://DevLists.com.  Sign up and save your mailbox.
>
>


-- 
Kevin Clark
http://glu.ttono.us