Where did I put that puts?

November 4th, 2009 by Radar

This 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.

Tags: ,

3 Responses to “Where did I put that puts?”

  1. Caffeine Driven Development » Blog Archive » L33t Links #38 Says:

    [...] Where did I put that puts? [...]

  2. Dan the Cheail Says:

    Why not put it in development.rb?

  3. Radar Says:

    Because I may also use it in tests.

Leave a Reply