Code After Rcov

The report generated by rake spec:rcov is good and helps me drop some old habit that i got from other than ruby languages. Take this method for instance:

48   def status
49     case status_code
50     when 'A'
51       :active
52     when 'Z'
53       :complete
54     else
55       nil
56     end
57   end

The line 54 & 55 were never tested, because the status codes are nothing supposed to be other than A or Z.

Ruby will return nil in any other case anyway, so I rewrote it to:

48   def status
49     case status_code
50     when 'A'
51       :active
52     when 'Z'
53       :complete
54     end
55   end

nice, 100% covered.

Leave a Comment