<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rob aldred &#187; actionmailer</title>
	<atom:link href="http://robaldred.co.uk/tag/actionmailer/feed/" rel="self" type="application/rss+xml" />
	<link>http://robaldred.co.uk</link>
	<description>cars, f1, bikes, tech tips &#38; what ever i&#039;m interested in this week</description>
	<lastBuildDate>Thu, 12 Aug 2010 15:01:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Testing ActionMailer models with Rspec</title>
		<link>http://robaldred.co.uk/2009/12/testing-actionmailer-models-with-rspec/</link>
		<comments>http://robaldred.co.uk/2009/12/testing-actionmailer-models-with-rspec/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 11:41:05 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionmailer]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://robaldred.co.uk/?p=163</guid>
		<description><![CDATA[You might think testing ActionMailer sounds like a challenge, actually it&#8217;s just as easy as testing other classes, you just have to know the methods to use to change the state/content of the deliveries. Here we have a simple example of how you might test a mailer for your order receipt 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475require File.dirname&#40;__FILE__&#41; + '/../spec_helper' [...]]]></description>
			<content:encoded><![CDATA[<p>You might think testing ActionMailer sounds like a challenge, actually it&#8217;s just as easy as testing other classes, you just have to know the methods to use to change the state/content of the deliveries.</p>
<p>Here we have a simple example of how you might test a mailer for your order receipt</p>
<div class="codecolorer-container ruby twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../spec_helper'</span><br />
<br />
describe OrderMailer <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; <br />
&nbsp; describe <span style="color:#996600;">&quot;receipt&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; <br />
&nbsp; &nbsp; before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@order</span> = mock_model<span style="color:#006600; font-weight:bold;">&#40;</span>Order<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@order</span>.<span style="color:#9900CC;">customer</span> = mock_model<span style="color:#006600; font-weight:bold;">&#40;</span>Customer<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; it <span style="color:#996600;">&quot;should render successfully&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> OrderMailer.<span style="color:#9900CC;">create_receipt</span><span style="color:#006600; font-weight:bold;">&#40;</span>@order<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">should_not</span> raise_error<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; describe <span style="color:#996600;">&quot;rendered without error&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span> = OrderMailer.<span style="color:#9900CC;">create_receipt</span><span style="color:#006600; font-weight:bold;">&#40;</span>@order<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have an order number&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.order_number'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@order</span>.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have order details&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.order_details&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have a billing address&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.billing.address&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have a delivery address&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.delivery.address&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have customer contact details&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#contact_details&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.landline'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@order</span>.<span style="color:#9900CC;">customer</span>.<span style="color:#9900CC;">landline</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.mobile'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@order</span>.<span style="color:#9900CC;">customer</span>.<span style="color:#9900CC;">mobile</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.email'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@order</span>.<span style="color:#9900CC;">customer</span>.<span style="color:#9900CC;">email</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have a list of items&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.line_items&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should have totals&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@mailer</span>.<span style="color:#9900CC;">body</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.totals&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.sub_total'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> format_price<span style="color:#006600; font-weight:bold;">&#40;</span>@order.<span style="color:#9900CC;">sub_total</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.vat'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> format_price<span style="color:#006600; font-weight:bold;">&#40;</span>@order.<span style="color:#9900CC;">vat</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.postage'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> format_price<span style="color:#006600; font-weight:bold;">&#40;</span>@order.<span style="color:#9900CC;">postage</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.total'</span>, <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> format_price<span style="color:#006600; font-weight:bold;">&#40;</span>@order.<span style="color:#9900CC;">total</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should deliver successfully&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> OrderMailer.<span style="color:#9900CC;">deliver</span><span style="color:#006600; font-weight:bold;">&#40;</span>@mailer<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">should_not</span> raise_error<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; describe <span style="color:#996600;">&quot;and delivered&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; it <span style="color:#996600;">&quot;should be added to the delivery queue&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> OrderMailer.<span style="color:#9900CC;">deliver</span><span style="color:#006600; font-weight:bold;">&#40;</span>@mailer<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">should</span> change<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">deliveries</span>,:size<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">by</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>rendering the following output:</p>
<div id="attachment_176" class="wp-caption alignnone" style="width: 310px"><a href="http://robaldred.co.uk/wp-content/uploads/2009/12/Screen-shot-2009-12-14-at-11.37.58.png"><img src="http://robaldred.co.uk/wp-content/uploads/2009/12/Screen-shot-2009-12-14-at-11.37.58-300x262.png" alt="ActionMailer test output from textmate rspec bundle" title="ActionMailer test output from textmate rspec bundle" width="300" height="262" class="size-medium wp-image-176" /></a><p class="wp-caption-text">ActionMailer test output from textmate rspec bundle</p></div>
]]></content:encoded>
			<wfw:commentRss>http://robaldred.co.uk/2009/12/testing-actionmailer-models-with-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
