This was asked back in 2008 but I’m wondering if there is an easier way
with rspec2 and rails. Seems like it would make my test log much more
meaningful. Surely somebody must have done it.
Is there an easy way to inject each example text into test.log so I
can isolate the log output per example?
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} ^^ ===”
end
end
RSpec.configure do |c|
c.after do |m|
Rails.logger.debug “=== ^^ #{m.example.full_description} ^^ ===”
Rails.logger.debug “=== ^^ #{m.example.location} ^^ ===”
end
end
I’m thinking this might be an interesting use case for a custom
formatter.