This is probably an easy question, though I couldn’t find anything in the RSpec docs.
When running RSpec for my little Ruby (not Rails!) program, the output of RSpec is messed up with the output of my program (e.g. custom warning messages I introduced (warn()) or progress messages to $stdout via puts).
How can I redirect only the output of my program to a file (or /dev/null)?
Do I have to mock $stdout, puts and warn every time? It would be not helpful as I’m not interested in that output for the tests.
I’m calling RSpec with rake and the following options:
--require spec_helper.rb \
--format html --out log/rspec_report.html \
--format documentation --out log/rspec_report.txt \
--format progress
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
rspec 2.8.0
rake 0.9.2.2
You can print your custom messages into $stderr instead of $stdout.
After that you will be able redirect error stream like: