<?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>One Man's Walk in work &#187; file sandbox</title>
	<atom:link href="http://onemanswalk.com/work/tag/file-sandbox/feed/" rel="self" type="application/rss+xml" />
	<link>http://onemanswalk.com/work</link>
	<description>jeremy lightsmith on agile, ruby, and consulting</description>
	<lastBuildDate>Wed, 04 May 2011 04:29:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Temp Files Pattern</title>
		<link>http://onemanswalk.com/work/2003/12/19/the-temp-files-pattern/</link>
		<comments>http://onemanswalk.com/work/2003/12/19/the-temp-files-pattern/#comments</comments>
		<pubDate>Fri, 19 Dec 2003 00:00:00 +0000</pubDate>
		<dc:creator>jeremy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[file sandbox]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[	This is a pattern I first started using while working on rublog w/ Brian Marick et al.  Dave Thomas gave it a better name when he checked it in, and I&#8217;ve renamed it since then.  I think I like temp files.  A second ago, I was working in nfit, and found myself [...]]]></description>
			<content:encoded><![CDATA[	<p>This is a pattern I first started using while working on rublog w/ Brian Marick et al.  Dave Thomas gave it a better name when he checked it in, and I&#8217;ve renamed it since then.  I think I like temp files.  A second ago, I was working in nfit, and found myself writing it in c#.  So I guess I like it.</p>

	<p><strong>Problem:</strong></p>

	<p>You want to test something that accesses files.  Something that you want to do all the time for some apps.</p>

	<p><strong>Solution:</strong></p>

	<p>Create a class called !TempFiles, use it like this (for ruby):</p>

	<p>
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> test_load
	files = TempFiles.<span style="color:#9900CC;">new</span>
	files.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'wiki/captions/2003_11-November_captions.txt'</span>, CONTENTS<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
	files.<span style="color:#9900CC;">create</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>dir<span style="color:#006600; font-weight:bold;">|</span>
		captions = Captions.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>Wiki.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>dir, <span style="color:#996600;">'/2003/11-November'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'/2003/11-November'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
		assert_equal<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Jilian'</span>, captions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'apPle.JPG'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		assert_equal<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'from the top'</span>, captions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'bitter.jpg'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>



	<p>It can be used from any test, and makes creating a file easy.  From ruby the blocks make it really nice.  I often add files in the setup code, but always have the block in the actual test.  The nice thing about this is it&#8217;s easy to add files in your test right before creating them.</p>

	<p>I&#8217;ll add the c# usage tomorrow</p>

	<ul>
		<li><span class="caps">UPDATE </span>*</li>
	</ul>

	<p>this is now a gem called file_sandbox &#8211; sudo gem install file_sandbox &#8211; enjoy&#8230;</p>
 ]]></content:encoded>
			<wfw:commentRss>http://onemanswalk.com/work/2003/12/19/the-temp-files-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

