如何显示RSpec测试生成的SQL查询日志? [英] How to show SQL query log generated by a RSpec test?

查看:79
本文介绍了如何显示RSpec测试生成的SQL查询日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的Rails 3应用程序编写规范.我想测试数据库事务是否确实有效.能够在规范驱动下查看我的应用程序生成的sql查询确实很有帮助.

I am writing a spec for my rails 3 application. I want to test that db transactions are really working. It would be really helpful to be able to see the sql queries being generated my app while being driven by the spec.

有没有办法像在Rails控制台中一样查看查询?

Is there a way to see the queries just like in the rails console?

我正在使用Rails 3.0.9,RSpec 2.6和sqlite(稍后将移至mysql)

I'm using Rails 3.0.9, RSpec 2.6, and sqlite (will move to mysql later on)

推荐答案

将其放入您的规格中:

ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base)

,然后您可以tail -f log/test.log看看发生了什么.一个,但不是两个.

and you can tail -f log/test.log and see what's happening. Either one but not both.

这篇关于如何显示RSpec测试生成的SQL查询日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆