Tom H.
2011-Jan-30 09:16 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
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? Thanks -- Posted via http://www.ruby-forum.com/.
Evgeniy Dolzhenko
2011-Jan-30 10:33 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
Do you need the full source code of an example in the log output, or just a description? On 1/30/2011 12:16 PM, Tom H. wrote:> 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? > > Thanks >
Tom H.
2011-Jan-30 11:00 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
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 -- Posted via http://www.ruby-forum.com/.
Evgeniy Dolzhenko
2011-Jan-30 12:00 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
RSpec.configure do |c| c.before do |m| Rails.logger.debug "==> #{m.example.full_description}" end end Cheers 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 >
Tom H.
2011-Jan-30 13:24 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
That worked a treat Thanks -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2011-Jan-30 14:16 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
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 > > endThat 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
Rick DeNatale
2011-Jan-30 16:39 UTC
[rspec-users] Is there an easy way to inject each example text into test.log
On Sun, Jan 30, 2011 at 9:16 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> 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} ^^ ===" > ?end > endI''m thinking this might be an interesting use case for a custom formatter. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale