1

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?

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.