
<?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>Bryce McDonnell &#124;&#124; Freelance Web Application Developer &#187; Rspec</title>
	<atom:link href="http://www.brycemcdonnell.com/skills-and-expert-groups/rspec/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brycemcdonnell.com</link>
	<description>bryce mcdonnell is a freelance web application developer specializing in PHP, Ruby on Rails and MySQL</description>
	<lastBuildDate>Fri, 26 Feb 2010 18:18:48 +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>Custom Routes with Shoulda</title>
		<link>http://www.brycemcdonnell.com/2010/02/custom-routes-with-shoulda/</link>
		<comments>http://www.brycemcdonnell.com/2010/02/custom-routes-with-shoulda/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 20:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Stuff I'm Working On]]></category>
		<category><![CDATA[Rspec]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.brycemcdonnell.com/?p=234</guid>
		<description><![CDATA[I&#8217;ve recently been using Shoulda as my testing framework of choice to speed up my Rspec test writing. One common pattern kept recurring which was totally vexing: I wasn&#8217;t able to test my custom routes. Just recently, I was writing a reviews controller that is mostly controlled by an admin user of the site. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been using <a title="thoughtbot's shoulda framwork" href="http://thoughtbot.com/community/" target="_blank">Shoulda</a> as my testing framework of choice to speed up my <a title="Rspec, a great ruby on rails testing framework" href="http://rspec.info/" target="_blank">Rspec</a> test writing. One common pattern kept recurring which was totally vexing: I wasn&#8217;t able to test my custom routes. Just recently, I was writing a reviews controller that is mostly controlled by an admin user of the site. It&#8217;s logical to route the index request of the reviews controller to /admin.</p>
<p>I kept trying to force the request with the following failing code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#don't use this, it's bad</span>
<span style="color:#008000; font-style:italic;"># I want to reroute /reviews to /admin</span>
get <span style="color:#996600;">&quot;/admin&quot;</span></pre></div></div>

<p>That was clearly wrong, but nothing immediately jumped out at me as to how to fix it. After much googling around, I finally found the quick and easy solution:<br />
<a title="ruby code as a gist" href="http://gist.github.com/309123" target="_blank">ruby code on github here</a></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">describe <span style="color:#996600;">&quot;/admin&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    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:#006600; font-weight:bold;">&#123;</span>
      get <span style="color:#ff3333; font-weight:bold;">:index</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    it <span style="color:#006600; font-weight:bold;">&#123;</span> should route<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:get</span>, <span style="color:#996600;">&quot;/admin&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:controller</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:reviews</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:index</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    it <span style="color:#006600; font-weight:bold;">&#123;</span> should respond_with<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:success</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Hope this saves someone else some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brycemcdonnell.com/2010/02/custom-routes-with-shoulda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
