Greg Hauptmann
2009-Apr-21 00:53 UTC
how to I see SQL trace when using (a) rails console & (b) running rspec tests???
Hi, I''d like to know how to monitor the SQL calls (from ActiveRecord) for both the cases: (a) using rails console [development mode], and (b) running rspec tests [test mode] How can I do this? For item (a) I recollect previously I could just run up a "./script/server" and see this whilst using "./script/console" however it does not seem to be working currently for me. Tks -- Greg http://blog.gregnet.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2009-Apr-21 01:00 UTC
Re: how to I see SQL trace when using (a) rails console & (b) running rspec tests???
On Apr 20, 2009, at 5:53 PM, Greg Hauptmann wrote:> Hi, > > I''d like to know how to monitor the SQL calls (from ActiveRecord) > for both > the cases: > (a) using rails console [development mode], and > (b) running rspec tests [test mode] > > How can I do this? For item (a) I recollect previously I could just > run up > a "./script/server" and see this whilst using "./script/console" > however it > does not seem to be working currently for me.Not sure about (b), but for (a) put this in your ~/.irbrc # Log to STDOUT if in Rails if ENV.include?(''RAILS_ENV'') && !Object.const_defined? (''RAILS_DEFAULT_LOGGER'') require ''logger'' RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) end
Phlip
2009-Apr-21 02:47 UTC
Re: how to I see SQL trace when using (a) rails console & (b) running rspec tests???
>> (b) running rspec tests [test mode]> Not sure about (b), but for (a) put this in your ~/.irbrcFor (b), gem install assert_efficient_sql, then put this around your RSpec money-line: inspect_sql :verbose => true do concoct_sql() end It will spew out your SQL statements, and their EXPLAIN results, so you can see the bottlenecks. It only works for MySQL tho... Also, put in require ''assert_efficient_sql'', and this: Spec::Runner.configure do |c| c.include Test::Unit::Assertions end -- Phlip http://flea.sourceforge.net/resume.html