3

I want to show each example's description in the Rails log during debugging. I can't quite figure out how this is done. I've looked at using RSpec.configure doing something like this:

RSpec.configure do |config|
  config.before(:each) do |example|
    Rails.logger.debug example.description
  end
end

but that just gives a NoMethodError as it can't find description at that point. I thought it might work like #around does, but I guess not.

tamouse
  • 2,169
  • 1
  • 19
  • 26
  • This should help : http://stackoverflow.com/a/10199575/429758 – Prakash Murthy Jan 17 '13 at 04:31
  • @PrakashMurthy actually, not at all. I know how to use the Rails logger, that's not the issue. What I want is to have each test's description written to the Rails log when it is run. I *don't* particularly want to have to edit every spec file to do this. – tamouse Jan 17 '13 at 04:44

1 Answers1

3

You're pretty close, the following will output your test descriptions as they're run:

RSpec.configure do |config|
   config.before(:each) do
     Rails.logger.debug self.class.description         
   end
end

Source: http://benmabey.com/2008/07/04/global-setup-in-rspec-or-how-to-add-logging-for-specs.html

Noz
  • 6,216
  • 3
  • 47
  • 82