[rspec-users] Depot app, Demeter's law and troubles cleanly specing

Mark Wilden mark at mwilden.com
Sat Apr 18 14:50:33 EDT 2009


On Sat, Apr 18, 2009 at 10:17 AM, Fernando Perez <lists at ruby-forum.com> wrote:
>
> @order.items.each do |item|
>  item.product.title
> end
>
> Now I'm having problems specing item.product.title. A quick and dirty
> fix is to trade a for for an underscore, so I create Item#product_title:
>
> def product_title
>  product.title
> end

And this still doesn't satifsy the "Law" of Demeter because you're
still calling order.items[x].product_title. Simply adding a method
call in between doesn't obviate the fact that you need the order's
item's product's title.

I would split the difference and have an orders helper that knew how
to format each component of a displayed item.

///ark


More information about the rspec-users mailing list