<?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>Thinking In Rails &#187; Testing</title>
	<atom:link href="http://thinkinginrails.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkinginrails.com</link>
	<description>A Perl Programmer&#039;s Exploration of The World of Ruby on Rails</description>
	<lastBuildDate>Fri, 20 Jan 2012 19:17:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Aaron Patterson&#8217;s Emoji Test Output Gem</title>
		<link>http://thinkinginrails.com/2011/11/aaron-pattersons-emoji-test-output-gem/</link>
		<comments>http://thinkinginrails.com/2011/11/aaron-pattersons-emoji-test-output-gem/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 22:11:20 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=662</guid>
		<description><![CDATA[Aaron Patterson &#8211; Google+ &#8211; I&#8217;m on vacation, so I decided to write a gem that WILL…. Just awesome stuff, my favorite yet. Make sure you follow Aaron on Google+ as well, lots of cool Ruby and Rails related stuff there. Via Reddit]]></description>
			<content:encoded><![CDATA[<p><a href="https://plus.google.com/117847179642773850013/posts/dqMAANkf7g5">Aaron Patterson &#8211; Google+ &#8211; I&#8217;m on vacation, so I decided to write a gem that WILL…</a>.</p>
<p>Just awesome stuff, my favorite yet. Make sure you follow Aaron on Google+ as well, lots of cool Ruby and Rails related stuff there.</p>
<p><center><iframe src="http://www.youtube.com/embed/5wUVvp1J9ZE" frameborder="0" width="420" height="315"></iframe></center>Via Reddit</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2011/11/aaron-pattersons-emoji-test-output-gem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thinking on The New Paradigm Of Web Application Development</title>
		<link>http://thinkinginrails.com/2010/07/thinking-on-the-new-paradigm-of-web-application-development/</link>
		<comments>http://thinkinginrails.com/2010/07/thinking-on-the-new-paradigm-of-web-application-development/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 05:45:56 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=600</guid>
		<description><![CDATA[This is probably old news to everyone who reads this, but today I had a bit of an epiphany.  I was watching Charles Max Wood&#8217;s excellent Teach Me To Code Screen-cast and realized (after watching two parts of his &#8220;building a blog&#8221; series) that he wasn&#8217;t ever actually looking at the output of his coding, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="Mind Blown Dude" src="http://3.bp.blogspot.com/_UKZle04oFnc/SFdGKUPYevI/AAAAAAAAAqw/FjFvQ5Jhf4Q/s400/dope%2Bexploding%2Bhead.jpg" alt="" width="305" height="400" />This is probably old news to everyone who reads this, but today I had a bit of an epiphany.  I was watching Charles Max Wood&#8217;s excellent <a href="http://www.teachmetocode.com/itunes.rss">Teach Me To Code Screen-cast</a> and realized (after watching <a href="http://teachmetocode.com/screencasts/rails-3-building-a-blog-part-1-test-setup-generators">two</a> <a href="http://teachmetocode.com/screencasts/rails-3-building-a-blog-part-2-crud-show-and-create">parts</a> of his &#8220;building a blog&#8221; series) that he wasn&#8217;t ever actually looking at the output of his coding, at least in the traditional sense.</p>
<p>The way I&#8217;ve coded since, well, forever has been like this.  I open up my editor window, and an output window.  When I was writing C code back in the dot com days this was another terminal with a &#8220;make &amp;&amp; ./app&#8221; in it, and in my newer web application days, a browser window with my mouse hand on the reload button. After a bit of code was written, I&#8217;d either hit &#8220;up-arrow enter&#8221; for C code or reload the browser, and see what&#8217;s happened.</p>
<p>Watching the screen-cast I realize that Charles was doing the following (as far as I can tell, as I&#8217;m pretty new to the whole <a href="http://thinkinginrails.com/2010/04/ruby-on-rails-lingo-for-beginners/">TDD thing</a>):</p>
<ul>
<li>Writing a scenario or feature (using <a href="http://wiki.github.com/aslakhellesoy/cucumber/">cucumber</a>)</li>
<li>Using that to generate tests (with <a href="http://rspec.info">rspec</a>, I think)</li>
<li>Running the test, watching it fail</li>
<li>Writing the code to make the test pass</li>
<li>Running the test, watching it pass</li>
<li>Repeat&#8230;</li>
</ul>
<p>Now the last four steps I do know about, those are standard TDD methodology, broken down into Red (write a failing test), Green (make it pass), Refactor (make the code better), but I was blown away with the realization that he wasn&#8217;t looking at the output of the code he was writing, but instead was letting the testing framework do the work, so instead of having to verify with your own eyes that the [insert web page you're interested in here] is showing properly, you have it checked programmatically, no browser needed (in fact, at the point in part two when the browser is needed, there&#8217;s that uncomfortable pause while FireFox groans and raises itself into a running state).</p>
<p>Is that what TDD is really about?  I&#8217;ve always imagined it as an augmentation to the previously-described way I used to code in that before I coded and reloaded the browser window you&#8217;d write the test, then the code, then the browser reload, then the test again to make sure it passed.</p>
<p>This is a whole new world that&#8217;s frankly thrown me for a loop, and into a fervor of reading up on <a href="http://wiki.github.com/aslakhellesoy/cucumber/">cucumber</a>.  I&#8217;m not sure how this will affect my code writing, but this makes the whole world of TDD a <em>lot</em> more interesting!  Course, I&#8217;ll have to re-watch the two episodes to make sure I truly grok the tools that he&#8217;s using.</p>
<p><strong>Further Reading / Links</strong></p>
<ul>
<li><a href="http://teachmetocode.com/screencasts/rails-3-building-a-blog-part-1-test-setup-generators">Part 1</a> and <a href="http://teachmetocode.com/screencasts/rails-3-building-a-blog-part-2-crud-show-and-create">Part 2</a> of the screencast in question</li>
<li><a href="http://teachmetocode.com/">Teach Me To Code Screencasts</a> (TMTC hold two coveted places on my <a href="http://thinkinginrails.com/2010/04/favorite-ruby-and-rails-podcasts/">list of programmer podcasts</a>)</li>
<li>@<a href="http://twitter.com/teachmetocode">teachmetocode</a> and @<a href="http://twitter.com/charlesmaxwood">charlesmaxwood</a> on Twitter</li>
<li>The <a href="http://webchat.freenode.net/?channels=teachmetocode">#teachmetocode</a> IRC channel on Freenode, come by and hang out and chat</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/07/thinking-on-the-new-paradigm-of-web-application-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Website Step 0 &#8211; Understanding RSpec</title>
		<link>http://thinkinginrails.com/2010/06/new-website-step-0-understanding-rspec/</link>
		<comments>http://thinkinginrails.com/2010/06/new-website-step-0-understanding-rspec/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 04:54:14 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=581</guid>
		<description><![CDATA[The more alert among you will have noticed that my &#8220;work one day, post the next&#8221; regarding my new project has pretty much fallen dead.  I&#8217;ve found this &#8220;testing&#8221; thing fairly difficult to get into.  Part of it is just the syntax or rspec, some of it is just the mindset required to to Test Driven Development. [...]]]></description>
			<content:encoded><![CDATA[<p>The more alert among you will have noticed that my &#8220;work one day, post the next&#8221; regarding my new project has pretty much fallen dead.  I&#8217;ve found this &#8220;testing&#8221; thing fairly difficult to get into.  Part of it is just the syntax or <a href="http://rspec.info/">rspec</a>, some of it is just the mindset required to to Test Driven Development.</p>
<ul>
<li>RSpec syntax takes a bit to get used to</li>
<li>RSpec philosphies take a bit to get used to&#8230;. understanding the :before block, lets, contexts, descriptions, and subjects are all great, but it&#8217;s even better to have an idea about the best practices associated with them</li>
<li>The overall idea of TDD.  Do you want to test the actions that a user is taking?  IE: &#8220;Create an object&#8221;, &#8220;alter an object&#8221;.  Or do you test each individual function in the system?  IE: new() create() destroy(), etc.  If the latter, are you expected to test all the functions you <em>don&#8217;t</em> create, ie: the built in object methods that you get when you have any class?</li>
<li>How far do you take TDD if you&#8217;re just trying to get a 3 function class off the ground?</li>
</ul>
<p>Luckily the test-driven @dkubb was there to help me out a bit, and gave me this <a href="http://github.com/arcterex/ruby-idioms.com/blob/a3ee25b197703fd6c5c7f5fc3b13594f123224a3/spec/models/idiom_spec.rb">nice setup to start with</a>.  This let me see the proper (or at least how Dan did it) setup for where a context/let/description/etc block goes.  All good stuff.</p>
<p>Now I have a model (so to speak) I can work from, so now I can finally get off my ass and get some code written.  Dan&#8217;s philosphy is that if you code for more than a few minutes at a time you&#8217;re doing something wrong, and you should be testing, coding, testing, coding and then doing some more testing before you do more coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/06/new-website-step-0-understanding-rspec/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pushing Through The Wall</title>
		<link>http://thinkinginrails.com/2010/04/pushing-through-the-wall/</link>
		<comments>http://thinkinginrails.com/2010/04/pushing-through-the-wall/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 15:24:57 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Fear]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=146</guid>
		<description><![CDATA[This entry was almost titled &#8220;In Which it All Comes Apart&#8221; because lately I&#8217;ve felt like all my previous forward motion with my Rails project has come to a crashing halt.  It seemed like the only time that I got work done was at the FV.rb meetups, but in the evenings I just didn&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>This entry was almost titled &#8220;<strong>In Which it All Comes Apart</strong>&#8221; because lately I&#8217;ve felt like all my previous forward motion with my Rails project has come to a crashing halt.  It seemed like the only time that I got work done was at the <a href="http://www.meetup.com/fvruby/">FV.rb</a> meetups, but in the evenings I just didn&#8217;t have any drive to do anything, and on the weekend when I did, I&#8217;d think about the current couple of tasks on my plate and get&#8230; scared is about the only real word for it, and just go back to watching TV, websurfing, or whatever other thing that <em>wasn&#8217;t</em> programming Ruby and Rails.  Not a good way to go.</p>
<p>Last night I finally broke through this a bit.  Amidst my mother-in-law drilling and cutting (she&#8217;s helping my wife put up cabinets) and my brother-in-law on the couch oohing and awwing over <a href="http://vancouver.en.craigslist.ca/search/?areaID=16&amp;subAreaID=&amp;query=excavator&amp;catAbbreviation=sss">heavy equipment ads on craigslist</a>, I managed to get things done.  I figure a bit of post-mortem might help me for the next time it happens.</p>
<p>The two things that I had on my plate were not, in fact, the only things needing to be done, but they were the two things that are fairly isolated and sort of simple.</p>
<p>The first was adding &#8216;areas&#8217; to my referee site.  Each club has many fields, each field has many games.  I wanted to expand this so that each club has many areas, and each area has many fields, and so on.  Basically this allows you to break up the &#8220;Langley&#8221; club into say, north south east and west, and assign users to various areas and make things a bit more manageable.  IE: Assignor Bob manages the north zone, while Manager Sue takes care of South and East.</p>
<p><a href="http://thinkinginrails.com/wp-content/uploads/2010/04/failingtests1.png"><img class="alignright" title="Failing Tests" src="http://thinkinginrails.com/wp-content/uploads/2010/04/failingtests1.png" alt="Failing Tests" width="461" height="166" /></a>Code wise it&#8217;s pretty simple, add a new model, add the &#8220;has_many&#8221; and &#8220;belongs_to&#8221; relationships, and create the management pages.  Simple stuff, so what&#8217;s the problem?</p>
<p>I think it might have come into the testing part again.  Because I&#8217;d have to rearrange some of my queries to ensure that users get the right games from the right fields from the (now) right areas from (<em>breath)</em> the right club, having no testing set up means that I&#8217;d have to go to all the pages that access that code, redo the queries, re-test, etc.  Ugh.</p>
<p>The second task that was a real stumbling block was the user and role management.  I had set up user authentication a while back, and if you log in as one of two user types you&#8217;d end up being sent to the &#8220;correct&#8221; page, and the two different controllers (/bids and /assignments) are protected through a before_filter as well, but I hadn&#8217;t gotten around to &#8220;Management&#8221; stuff (editing games, fields, etc) yet.</p>
<p>The big mental block that I had in this area was that I had 3 fairly clearly defined roles, 4 if you include the &#8220;unauthenticated&#8221; users.  I had</p>
<ul>
<li>Referee (can bid on games)</li>
<li>Assignor (approves/edits referee bids)</li>
<li>Club Admin (club management stuff)</li>
</ul>
<p>All the stuff in the User model is geared towards these, a club_id is defined and required, email is required, etc.</p>
<p>The role that <em>wasn&#8217;t</em> so easily defined was the &#8220;master&#8221; admin.  This is the main user that would manage the whole site, set up clubs, and basically have access to <strong>everything</strong>.  I faced the challenge of either creating a new type of authentication and model (ignoring the DRY principle), putting a bunch of exceptions in (ie: requires validation of club_id <strong>unless</strong> this user has a role type of &#8216;masteradmin&#8217;) and making things ugly.</p>
<p>I managed to push through the first one, or at least start to.  I&#8217;ve managed to get to the scaffolding part anyway.  Also in my lunch hours I&#8217;ve started going at the failing tests too.  That&#8217;s a whole other blog post though, probably involving me going back to the simplest cases that are in the <a href="http://www.railstutorial.org/">Rails Tutorial</a> book and figuring out how to deal with speccing out password protected pages <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/04/pushing-through-the-wall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Need For Testing</title>
		<link>http://thinkinginrails.com/2010/04/the-need-for-testing/</link>
		<comments>http://thinkinginrails.com/2010/04/the-need-for-testing/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 03:44:30 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Fear]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://thinkinginrails.com/?p=137</guid>
		<description><![CDATA[In which I discover that yes Virginia, there is a good reason to write tests from the start. I think I saw testing originally as a really nice thing to do in theory, but something that was quickly glossed over when you have your boss looking over your shoulder and wondering just why your project [...]]]></description>
			<content:encoded><![CDATA[<p>In which I discover that yes Virginia, there <em>is</em> a good reason to write tests from the start.</p>
<p>I think I saw testing originally as a really nice thing to do in theory, but something that was quickly glossed over when you have your boss looking over your shoulder and wondering just why your project was late, just write the damn thing.</p>
<p>I actually discovered testing in Perl around 2003 with Test::Unit, when I was working at a company that did an online game site for school students.  I read about testing, grabbed Test::Unit and Test::More and proceeded to do add some rudimentary tests to the model to do things like ensure that instantiating a new User model always created an object of the right type, that sort of thing.</p>
<p>I proudly told my boss this.  His response was something like &#8220;neat&#8221;, with the unspoken subtext of &#8220;why aren&#8217;t you doing your work and wasting time doing this&#8221;.</p>
<p>Fast forward to the TDD happy fun world of rails.</p>
<p>I&#8217;m now a couple of weeks into my referee management site.  It&#8217;s got a non-trivial, but not hugely complex set of models and interactions and I want to make some (moderately) major changes in some of the architecture.  It <em>terrifies</em> me (well, maybe terrify is too strong a word) to make these changes without being able to just hit a button and know, <strong>know</strong>, that everything still works properly.</p>
<p>I started creating my models and controllers based on the <a href="http://www.railstutorial.org">Rails Tutorial</a> site and using the &#8220;rspec_&#8221; syntax.  IE:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>generate rspec_controller Foo</pre></div></div>

<p>This creates a set of default <a href="http://rspec.info/">RSpec</a> tests.  Of course, the defaults are standard stuff, making sure that creating the object returns the right type of object, etc. Luckily a bit later on in the book there is a section on <a href="http://www.railstutorial.org/chapters/static-pages#sec:first_tests">setting up your first tests</a>.</p>
<p>The first challenge I have to create some of my tests (again harkening back to my &#8220;rails makes it seem <em>sooo</em> easy, but when you do it it&#8217;s a lot harder&#8221; rant), is that most of the pages on the site (that do interesting things anyway) are password protected. So now it&#8217;s a trek to find out how to deal with speccing out pages that are password protected to help fix the 24 failed tests I have sitting now when I run &#8216;spec spec&#8217; <img src='http://thinkinginrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So let that be a lesson to you all&#8230;. do your testing from the start, and set it up <strong><em>from the start</em></strong> like I should have (and knew I should have).</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkinginrails.com/2010/04/the-need-for-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

