Passionate Engineer
Passionate Engineer

Reputation: 10412

How to test RSpec tests output in command line

I'm running tests that returns puts to console with return value as nil

Problem is that I'm now getting puts output coming out whenever I run tests with RSpec.

How would you test this output and make sure no output is showing up in test console?

Upvotes: 1

Views: 565

Answers (1)

David Grayson
David Grayson

Reputation: 87386

One way would be to refactor the code so that it takes an IO object as input and gives its output by calling puts on that. In normal use, use $stdout but in your tests use a StringIO object.

If that is not feasible, you might consider inside your tests defining a special puts method in the class being tested. This would hide the real puts method.

Upvotes: 2

Related Questions