How come commands like puts and print don't show up in the console when running ActiveSupport::TestCase tests?
Makes it very hard to debug if I can't outputs some inspections in a couple of methods.
Thanks!
You can use the rails logger to see your output:
Rails::logger.debug "Interesting stuff"
Run tail -f log/test.log
on the command line (from the project's root in a separate Terminal tab or window) to see the results.
I've just been struggling with this under rails (3.2). I don't know how things have changed between versions but the answers don't actually answer the question. Rather using
$stdout.puts msg
outputs to the console along with the other console messages when running individual tests.
I use puts all the time in tests when I'm quickly hacking debugging a single test. So I don't use rake test:*, rather run the individual test and the output shows up.
ruby -Itest test/unit/user/context_test.rb
You can use puts in an individual test as follows eg:
puts "\n\n #{@object.name}"
This will look something like as follows in your terminal window as the tests run
Started E...EEE
United Kingdom .E
Finished in 2.787886 seconds.
(where @object.name == "United Kingdom"
in this case)
It's quite a crude method but very quick for simple debugging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With