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."
endWithout 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access