Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 661
lzap Avatar asked Mar 09 '11 10:03

lzap


2 Answers

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) 
like image 54
George Avatar answered Sep 17 '22 15:09

George


By default, all your db queries will be logged already in test mode. They'll be in log/test.log.

like image 35
idlefingers Avatar answered Sep 16 '22 15:09

idlefingers