<?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>netCUBED Blog &#187; time</title>
	<atom:link href="http://blog.netcubed.de/tag/time/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.netcubed.de</link>
	<description>Just another web developer's weblog</description>
	<lastBuildDate>Mon, 29 Jun 2009 20:58:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CPAN: Test::MockTime, Time Saver!</title>
		<link>http://blog.netcubed.de/2009/04/cpan-testmocktime-time-saver/</link>
		<comments>http://blog.netcubed.de/2009/04/cpan-testmocktime-time-saver/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 13:17:39 +0000</pubDate>
		<dc:creator>Moritz Onken</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[mocktime]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://blog.netcubed.de/?p=31</guid>
		<description><![CDATA[I recently had to test my model which has a method which depends on DateTime-&#62;now. The problem with testing is, that the returned value will change depending on the current time.
I could have copied the logic from the model&#8217;s method but that would have made the test obsolete. Instead I choose to mock the current [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to test my model which has a method which depends on DateTime-&gt;now. The problem with testing is, that the returned value will change depending on the current time.</p>
<p>I could have copied the logic from the model&#8217;s method but that would have made the test obsolete. Instead I choose to mock the current time and looked for a proper module on CPAN. And was lucky: <a href="http://search.cpan.org/perldoc?Test::MockTime">Test::MockTime</a> does just what I want:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Test<span style="color: #339933;">::</span><span style="color: #006600;">MockTime</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>set_absolute_time<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
set_absolute_time<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'2009-04-24T00:00:00Z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s it!</p>
<p>But make shure you load modules like DateTime <strong>after</strong> Test::MockTime!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.netcubed.de/2009/04/cpan-testmocktime-time-saver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
