How do I turn on SQL debug logging for ActiveRecord in RSpec tests?

lzap picture lzap · Mar 9, 2011 · Viewed 63.7k times · Source

I have some RSpec tests for my models and I would like to turn on SQL ActiveRecord logging just like I see in the Rails server mode. How to do that?

I start my tests with

RAILS_ENV=test bundle exec rspec my/test_spec.rb

Thanks

Answer

George picture George · Apr 1, 2011

You could try setting the ActiveRecord logger to stdout in your test somewhere. If you're using rspec, maybe in the spec helper?

ActiveRecord::Base.logger = Logger.new(STDOUT)