November 2007 - Posts

  • Why I hate test coverage tools
    Because it could lie if we abuse it. I have been in one project where people count acceptance tests (written in FIT) so the test coverage always looks pretty high when the unit tests coverage are actually poor. But the figure gave people there false confidence that their code is in good shape. In another project, a test had only two lines of code, but it actually ran about 5 seconds and touched a lot of code underneath. So by this test alone, it improved the test coverage a lot, looks pretty good eh? Then wait until it failed sometimes. People had...
    read more
  • Permalink: Monday, November 19, 2007 3:42 PM
    Posted by ywen | 1 Comments
    Filed under ,
  • When RSpec meets Validatable
    Jay Fields writes an excellent module called Validatable to provide a class who include the module the ActiveRecord like behavior. For example, you can say validates_presence_of :attribute etc. This page has the RDoc of the module. When I write RSpec for a Validatable class, I ended up writing a stattement like this: @email.validate_only("presence_of/body") @email.errors.on(:body).should_not be_nil Which is basically testing body is a required field. It works, but it looks complicated and hard to understand. The RSpec on Rails plugin provides a...
    read more
  • Permalink: Monday, November 12, 2007 10:36 AM
    Posted by ywen | 0 Comments
    Filed under , ,
  • Law of Demeter and Forwardable
    Dan Manges has an excellent post explaining Law of Demeter and when it makes sense to use Forwardable to comply the principle, or I should say when it doesn't make sense to use the module. The point is, use it when it makes sense. Take his example, customer_name is just not a sensible method for an order. Asking an order for its customer name is a wrong question because all the order should care is who is its customer. The name is irrelevant to the order. In fact, I think by putting cusomer_name method in an order. the encapsulation is actually...
    read more
  • Permalink: Friday, November 02, 2007 1:26 PM
    Posted by ywen | 0 Comments
    Filed under