Step 1: Fix the Spacing

A quick scan of the code reveals that while the test code is spaced reasonably nicely, the class itself is in a bit of a mess. Nothing is lined up. The flow of the method is confusing. And it takes just too much mental work to figure out what is going on.

Let’s see what happens though, if we indent things properly and we inject a few well-placed lines of whitespace.

 class​ MeterPrinter
 
 def​ print(m)
 
  r = StringIO.new
 
 case​ m.type
 when​ ​'gas'
  r << ​"Meter Report​​\n​​"
  r << ​"Type: Gas​​\n​​"
  r << ​"Construction Co. Ltd.​​\n​​"
 when​ ​'wind'
  r << ​"Meter Report​​\n​​"
  r << ​"Type: Wind​​\n​​"
  r << ​"Construction Co. Ltd.​​\n​​"
 when​ ​'solar'
  r << ​"Meter Report​​\n​​"

Get The Way of the Web Tester 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.