Playing the Game

images/programming/meter.png

Dave and crew are in a bit of a bind. They’ve got some code and tests that print a simple little report for each type of meter on their various work permits, but the engineer who did most of the work has moved on and nobody seems to be able to make heads or tails of the code.

Knowing he can count on you, he asks you to take a look at the code and see if there’s anything you can do to improve it.

Here’s the class and test code for the meter printing feature:

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

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.