<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: (Inglês) Explicit intent</title>
	<atom:link href="http://rafanoronha.net/explicit-intent/feed/" rel="self" type="application/rss+xml" />
	<link>http://rafanoronha.net/explicit-intent/</link>
	<description>closing the gap between business and technology</description>
	<lastBuildDate>Sat, 10 Jul 2010 16:09:20 -0300</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: rafanoronha</title>
		<link>http://rafanoronha.net/explicit-intent/comment-page-1/#comment-1493</link>
		<dc:creator>rafanoronha</dc:creator>
		<pubDate>Mon, 21 Sep 2009 19:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://rafanoronha.net/?p=649#comment-1493</guid>
		<description>Patrick,

Thx for your reply.
Your code seems pretty good, you hid the mockering noise in a nice way.

Despite the provided sample, my purpose was to talk about the importance of clarifying intent while we are writing code.

And it seems that, like me, you take this technique seriously.</description>
		<content:encoded><![CDATA[<p>Patrick,</p>
<p>Thx for your reply.<br />
Your code seems pretty good, you hid the mockering noise in a nice way.</p>
<p>Despite the provided sample, my purpose was to talk about the importance of clarifying intent while we are writing code.</p>
<p>And it seems that, like me, you take this technique seriously.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Reagan</title>
		<link>http://rafanoronha.net/explicit-intent/comment-page-1/#comment-1492</link>
		<dc:creator>Patrick Reagan</dc:creator>
		<pubDate>Mon, 21 Sep 2009 19:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://rafanoronha.net/?p=649#comment-1492</guid>
		<description>Rafael - 

I don&#039;t think that your suggested refactoring provides the clarity that you were looking for in the original sample you provided.  After the refactoring, we&#039;re still left with the original issue - by encapsulating the order&#039;s total inside the helper method it is hidden from each of the specs.  I think a better approach would be to just create a more meaningful describe block and embed the setup code there instead of bothering with a separate method as a label for your setup state.  After all, that&#039;s what before blocks are for.

In keeping with the theme of explicit intent, I tweaked your example so that I could provide a meaningful setup state in each of the specs:

&lt;code&gt;
describe CreditcardPayment do

  def initialize_payment_for_completed_order(order_options)
    total         = options[:total]
    payment_total = options[:payment_total]
    
    order = Order.new
    order.checkout_complete = true
    order.stub!(:total).and_return(total)
    order.stub!(:payment_total).and_return(payment_total)
  
    payment = CreditcardPayment.new(:order =&gt; order)
    
    payment, order
  end
  
  describe &quot;when saving&quot; do
    it &quot;should mark the order as paid if payment_total = total&quot; do
      payment, order = initialize_payment_for_completed_order(:total =&gt; 100, :payment_total =&gt; 100)
      order.should_receive(:pay!)
      
      payment.save
    end
    
    it &quot;should mark order as paid if payment_total &gt; total&quot; do
      payment, order = initialize_payment_for_completed_order(:total =&gt; 100, :payment_total =&gt; 101)
      order.should_recieve(:pay!)
      
      payment.save
    end
    
    it &quot;should not mark order as paid if payment_total  100, :payment_total =&gt; 99)
      order.should_not_receive(:pay!)
      
      payment.save
    end
  end
  
end
&lt;/code&gt;

I&#039;ts the difference in :total and :payment_total that are important in each of these specs, so they should remain where they present the most clarity.  I still don&#039;t really like this, but I think the awkwardness of the return values from my helper method hint at a design problem (which is what specs are for!).  I would refactor the implementation code to have the Order delegate to the CreditcardPayment class, and then have Order interrogate its associated payments and manage its own state.</description>
		<content:encoded><![CDATA[<p>Rafael &#8211; </p>
<p>I don&#8217;t think that your suggested refactoring provides the clarity that you were looking for in the original sample you provided.  After the refactoring, we&#8217;re still left with the original issue &#8211; by encapsulating the order&#8217;s total inside the helper method it is hidden from each of the specs.  I think a better approach would be to just create a more meaningful describe block and embed the setup code there instead of bothering with a separate method as a label for your setup state.  After all, that&#8217;s what before blocks are for.</p>
<p>In keeping with the theme of explicit intent, I tweaked your example so that I could provide a meaningful setup state in each of the specs:</p>
<p><code><br />
describe CreditcardPayment do</p>
<p>  def initialize_payment_for_completed_order(order_options)<br />
    total         = options[:total]<br />
    payment_total = options[:payment_total]</p>
<p>    order = Order.new<br />
    order.checkout_complete = true<br />
    order.stub!(:total).and_return(total)<br />
    order.stub!(:payment_total).and_return(payment_total)</p>
<p>    payment = CreditcardPayment.new(:order =&gt; order)</p>
<p>    payment, order<br />
  end</p>
<p>  describe "when saving" do<br />
    it "should mark the order as paid if payment_total = total" do<br />
      payment, order = initialize_payment_for_completed_order(:total =&gt; 100, :payment_total =&gt; 100)<br />
      order.should_receive(:pay!)</p>
<p>      payment.save<br />
    end</p>
<p>    it "should mark order as paid if payment_total &gt; total" do<br />
      payment, order = initialize_payment_for_completed_order(:total =&gt; 100, :payment_total =&gt; 101)<br />
      order.should_recieve(:pay!)</p>
<p>      payment.save<br />
    end</p>
<p>    it "should not mark order as paid if payment_total  100, :payment_total =&gt; 99)<br />
      order.should_not_receive(:pay!)</p>
<p>      payment.save<br />
    end<br />
  end</p>
<p>end<br />
</code></p>
<p>I&#8217;ts the difference in :total and :payment_total that are important in each of these specs, so they should remain where they present the most clarity.  I still don&#8217;t really like this, but I think the awkwardness of the return values from my helper method hint at a design problem (which is what specs are for!).  I would refactor the implementation code to have the Order delegate to the CreditcardPayment class, and then have Order interrogate its associated payments and manage its own state.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
