From: "Pedro CĂ´rte-Real" Date: 2006-07-28T20:05:37+09:00 Subject: Re: Wrapped method causing infinite recursion in rcov On 7/27/06, Mauricio Fernandez wrote: > If you cannot show me your code, please keep a copy of the codebase exhibiting > the bug. I might send you a modified rcov for you to test, if I can figure > this out. I can send you the code if you want but you've pretty much seen it all. assert_valid_markup is a plugin: http://wiki.rubyonrails.com/rails/pages/Assert+Valid+Markup+Plugin I just wrapped the call to that assertion so that on every successful request the HTML is tested. Other than that it's just normal tests. Just say so if you still can't reproduce it. > Actually, I think I know what is going on: when running under rcov, the file > holding your Rails test helper is being require()d twice. If I'm right, it > should be possible to infer what is going on by tracing #require, with e.g. > > module Kernel > req = instance_method(:require) > define_method(:require) do |*a| > puts "-" * 80 > puts "Kernel#require " + a.inspect > puts caller.inspect > req.bind(self).call(*a) > end > end > > and then looking for the calls where your test file was loaded. Things should > be easy until that stage. After that, we'd have to see why rcov introduces a > difference in the second call. > > [Thinking as I write] rcov loads the files supplied in the command line with > Kernel#load, so if you later #require' any of them, it would be loaded twice. > Moreover, Rake's default test loader also works this way; here's its source > code: > > ARGV.each { |f| load f unless f =~ /^-/ } > > If this hunch is correct, the following patch to bin/rcov could save the day: > > > diff -rN -u old-tmp/bin/rcov new-tmp/bin/rcov > --- old-tmp/bin/rcov 2006-07-27 21:50:33.000000000 +0200 > +++ new-tmp/bin/rcov 2006-07-27 21:50:33.000000000 +0200 > @@ -450,7 +450,7 @@ > if options.replace_prog_name > $0 = File.basename(File.expand_path(prog)) > end > - load prog > + require prog > end No, doesn't work :( > It was most probably discovered by some anonymous Japanese Rubyist before I > popularized it to some extent, though :) Thanks anyway. Pedro.