[rspec-users] Is there an easy way to inject each example text into test.log

David Chelimsky dchelimsky at gmail.com
Sun Jan 30 09:16:08 EST 2011

On Jan 30, 2011, at 6:00 AM, Evgeniy Dolzhenko wrote:

> On 1/30/2011 2:00 PM, Tom H. wrote:
>> Evgeniy Dolzhenko wrote in post #978481:
>>> Do you need the full source code of an example in the log output, or
>>> just a description?
>> Just the description would be good so I can match up the log entries to
>> the spec
> RSpec.configure do |c|
>  c.before do |m|
>    Rails.logger.debug "==> #{m.example.full_description}"
>  end
> end

That won't work if you use one liners (`it { should do_something }`) because the full_description isn't generated until after the example runs.

You _could_ do it in an after hook instead. I'd also include the location information so you can get right to the example if you need to:

RSpec.configure do |c|
 c.after do |m|
   Rails.logger.debug "=== ^^ #{m.example.full_description} ^^ ==="
   Rails.logger.debug "=== ^^ #{m.example.location} ^^ ==="

More information about the rspec-users mailing list