[rspec-users] Testing console IO / Re: Selectively ignoring exceptions in examples

Ash Moran ash.moran at patchspace.co.uk
Tue Aug 30 16:59:37 EDT 2011

On 30 Aug 2011, at 19:24, Alex Chaffee wrote:

> ...or grabbing and reassigning $stdout and $stderr, which is what
> "capturing" does.
> The basic idea is that Ruby is *already* decoupled from stdin/out/err
> via its dynamic nature and $globals. I get that by naming the inputs
> explicitly you're ensuring 100% compliance but you should consider
> whether it's worth it. Passing around DI clumps (aka "value objects"
> or "parameter objects" in some circles) can make your code a lot less
> concise, and concision is one of the great joys of Ruby.

Yes, I've done constant reassigning in the past, with before/after blocks to control the environment. I wasn't specifically avoiding that here, it's just what fell out my my initial design to pass the standard streams in as variables from the bin/ command. I'm going to see how it pans out, as I've never been so strict about IO before. 

> btw apologies if you already know this, but inside a normal Ruby
> program you should always use $stderr/$stdout/$stdin, not
> STDERR/STDOUT/STDIN since the former are settable and the latter are
> hardcoded to the "real" streams and, as true CONSTANTS, not easy to
> change. For whatever reason I see the caps versions used a lot more
> than the dollar versions, which is a shame.

Actually I didn't know that, so thanks for pointing it out :-)  Although I have often been puzzled by the presence of both forms…



More information about the rspec-users mailing list