Showing only specific test case in test.log

113 views Asked by At

I am writing Rails tests using the standard Test::Unit/TestCase.

Is there any way to somehow filter what gets printed to the log, so that you only print the stack for specific test cases.

I have a functional test file with many test cases in it, and I'm really only interested in debugging one test case. Printing my own log statements still requires searching through a few thousand lines of generated log. Or something similar to the RSpec 'pending' functionality.

2

There are 2 answers

1
Phlip On BEST ANSWER

Run from a command line ruby test/unit/my_model.rb to run one test suite. You can also use a debugger, such as (wrapped by) RubyMine or pry, to stop on a specific test case and look at the log.

But if a sledge-hammer does not solve the problem, you can use tweezers: config.logger.level = Logger::WARN in your test.rb, from Set logging levels in Ruby on Rails

2
OneChillDude On

It is probably better if instead of strangling the output to log/test.log, you become familiar with a command such as grep. Grep allows you to run very advanced search queries through files or directories, as long as your running on some flavor of *nix. The simplest use would be

grep search_term file_name

The reason I say you shouldn't constrict the log output is because someday that could bit you in the **s. Hope this helps.