Where did I put that puts?
November 4th, 2009 by RadarThis is the question I ask after I’ve just finished a massive debugging session and I run the tests and halfway through there’s something vague like “S3″ printed out. So I do a Cmd+Shift+F looking for that string and of course it doesn’t exist. What’s a guy to do?
Well, at Mocra we put this in our config/environment.rb file (although a better location would be in a required file located somewhere in lib, probably named debug.rb):
# Print the location of puts/p calls so you can find them later
def puts str
super caller.first if caller.first.index("shoulda.rb") == -1
super str
end
def p obj
puts caller.first
super obj
end
And when we don’t want it we comment it out. This will give us the exact location of the puts so we can track it down and remove it.

November 4th, 2009 at 6:38 pm
[...] Where did I put that puts? [...]
November 6th, 2009 at 11:35 am
Why not put it in development.rb?
November 7th, 2009 at 5:13 pm
Because I may also use it in tests.