1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
# Verbose Logging
Sometimes digging through logs is the best way to figure out what's going on.
When you run your test suite, logs are not printed out by default (although written to `test.log` – who cares?).
We provide a recipe to turn verbose logging for a specific example/group.
**NOTE:** Rails only.
## Instructions
Drop this line to your `rails_helper.rb` / `spec_helper.rb` / `test_helper.rb` / whatever:
```ruby
require "test_prof/recipes/logging"
```
### Log everything
To turn on logging globally use `LOG` env variable:
```sh
# log everything to stdout
LOG=all rspec ...
# or
LOG=all rake test
# log only Active Record statements
LOG=ar rspec ...
```
### Per-example logging
**NOTE:** RSpec only.
Activate logging by adding special tag – `:log`:
```ruby
# Add the tag and you will see a lot of interesting stuff in your console
it "does smthng weird", :log do
# ...
end
# or for the group
describe "GET #index", :log do
# ...
end
```
To enable only Active Record log use `log: :ar` tag:
```ruby
describe "GET #index", log: :ar do
# ...
end
```
### Logging helpers
For more granular control you can use `with_logging` (log everything) and
`with_ar_logging` (log Active Record) helpers:
```ruby
it "does somthing" do
do_smth
# show logs only for the code within the block
with_logging do
# ...
end
end
```
**NOTE:** in order to use this helpers with Minitest you should include the `TestProf::Rails::LoggingHelpers` module manually:
```ruby
class MyLoggingTest < Minitest::Test
include TestProf::Rails::LoggingHelpers
end
```
|