Capturing the Essence of a Defect
Before you can begin to hunt down a bug, you need to be able to reproduce it in isolation. The main idea is that if you remove all the extraneous code that is unrelated to the issue, it will be easier to see what is really going on. As you continue to investigate an issue, you may discover that you can reduce the example more and more based on what you learn. Because I have a real example handy from one of my projects, we can look at this process in action to see how it plays out.
What follows is some Prawn code that was submitted as a bug report.
The problem it’s supposed to show is that every text span()
resulted in a page break happening, when
it wasn’t supposed to:
Prawn::Document.generate("span.pdf") do span(350, :position => :center) do text "Here's some centered text in a 350 point column. " * 100 end text "Here's my sentence." bounding_box([50,300], :width => 400) do text "Here's some default bounding box text. " * 10 span(bounds.width, :position => bounds.absolute_left - margin_box.absolute_left) do text "The rain in Spain falls mainly on the plains. " * 300 end end text "Here's my second sentence." end
Without a strong knowledge of Prawn, this example may already seem
fairly reduced. After all, the text represents a sort of abstract problem
definition rather than some code that was ripped out of an application,
and that is a good start. But upon running this code, I noticed that the
defect was present whenever a span()
call was made. This ...
Get Ruby Best Practices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.