[rspec-users] getting output of STDOUT in spec

aslak hellesoy aslak.hellesoy at gmail.com
Tue Apr 10 12:04:36 EDT 2007


This is a variant of the dependency injection principle. It goes hand
in hand with mocking. I recommend martin fowler's DI article for more
info.

On 4/10/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
>
> On 10 Apr 2007, at 13:21, aslak hellesoy wrote:
>
> > def name_to_terminal(io=STDOUT)
> >   io.puts "Scott Taylor"
> > end
> >
> > then call it from a spec passing in a mock for io with the appropriate
> > expectation
>
> Aha - this gives me an idea about the dreaded "current-time" problem
>
> def do_something(time_factory=Time)
>    time = time_factory.new
>    # ...
> end
>
> Actually I suppose it works for any class.  Why didn't I think of
> that before?  It's so simple!
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list