<?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>Erics Tech Blog &#187; testing</title>
	<atom:link href="http://eric.lubow.org/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://eric.lubow.org</link>
	<description>Thoughts, musings, and other idealistic (sometimes useful) systems and development hoopla.</description>
	<lastBuildDate>Fri, 18 Nov 2011 14:56:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Should I Mock Kernel#exit</title>
		<link>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/</link>
		<comments>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 09:00:44 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=695</guid>
		<description><![CDATA[I don&#8217;t know what the right answer is, so any insight would be appreciated. From Googling around, I came across this thread on StackOverflow which talks about Validating exits and aborts in Rspec. I have a few issues with this, namely that I am using shoulda and I don&#8217;t want to validate the exit, I [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know what the right answer is, so any insight would be appreciated.  From Googling around, I came across this thread on <a href="http://www.stackoverflow.com">StackOverflow</a> which talks about <a href="http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec">Validating exits and aborts in Rspec</a>. I have a few issues with this, namely that I am using <a href="http://github.com/thoughtbot/shoulda">shoulda</a> and I don&#8217;t want to validate the exit, I want to stop it from happening inside of the test.<br />
<span id="more-695"></span><br />
I have figured out that <strong>rescue</strong>ing a Kernel#exit with afford the same opportunity to test results so I am not sure if mocking it is necessary.  Consider the following code which doesn&#8217;t involve mocking:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">class</span> Application<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> thread_cleanup<span style="color:#006600; font-weight:bold;">&#40;</span>threads<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; threads.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>thread<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thread.<span style="color:#9900CC;">kill</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Terminating...&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">exit</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 />
<br />
&nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># test cases</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">class</span> ApplicationTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;should <span style="color:#996600;">&quot;kill all threads and exit cleanly&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threads = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threads.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application.<span style="color:#9900CC;">thread_cleanup</span><span style="color:#006600; font-weight:bold;">&#40;</span>threads<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">SystemExit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assert_equal <span style="color:#006666;">0</span>, e.<span style="color:#9900CC;">status</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &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></div></div>
<p>Here we <strong>rescue</strong> the exit and continue on with the testing.  The tests don&#8217;t actually exit (which allows the suite to continue) and no mocking of core functionality is required.  Is it the better way? I don&#8217;t know, but it works.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/' rel='bookmark' title='Multiple Input Locations From Bash Into Ruby'>Multiple Input Locations From Bash Into Ruby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Peertester Community Testing</title>
		<link>http://eric.lubow.org/2010/tips/peertester-community-testing/</link>
		<comments>http://eric.lubow.org/2010/tips/peertester-community-testing/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:00:02 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=619</guid>
		<description><![CDATA[I am all about community and people participating in a community. Its the way social media succeeds. But there are non-social media communities out there too (yes I know that&#8217;s shocking). I was recently asked to participate in a beta testing for Peer Tester. I think this is an absolutely fantastic idea. Developers helping other [...]]]></description>
			<content:encoded><![CDATA[<p>I am all about community and people participating in a community.  Its the way social media succeeds.  But there are non-social media communities out there too (yes I know that&#8217;s shocking). I was recently asked to participate in a beta testing for <a href="http://www.peertester.com/">Peer Tester</a>.  I think this is an absolutely fantastic idea.  Developers helping other developers test their apps.  Hats off to the guys and gals over at <a href="http://www.engineyard.com/">Engine Yard</a> for designing and putting this application together.  Other than the fact that I got tired of looking at that olive green color after years in the military, this site is an great tool for developers.<br />
<span id="more-619"></span><br />
So now you&#8217;re probably asking what exactly it is.  Well, you create an account and then create tests for your web application.  The tester will then follow your instructions, clicking on what you tell them to do or reading what you tell them to read.  Then they are asked questions (multiple choice, short answer, or whatever suits the situation) while they are going through the testing.  You can then view their feedback and modify (or not modify) your application accordingly.</p>
<p>For people like me who absolutely suck at flow and visual aesthetics, this is great to see if others think your product elicits the expected reaction.  You can even specify the number of people you want to use as a sample size for testing.  But just like with any good community site, you need to participate in order to have the site excel.  You gain points and get badges for participation and bug finding.</p>
<p>Remember, the site is still in beta (and I can only hope that it will change the site color before it gets out of beta, but that&#8217;s me) so there may be some bugs.  I encourage everyone to take a look.  A little extra application testing never hurt anyone.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/social-networking/community-participation/' rel='bookmark' title='Community Participation'>Community Participation</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/testing-sessions-with-digestsha256-passwords-in-rails/' rel='bookmark' title='Testing Sessions with Digest::SHA256 Passwords In Rails'>Testing Sessions with Digest::SHA256 Passwords In Rails</a></li>
<li><a href='http://eric.lubow.org/2009/misc/social-media-information-propagation/' rel='bookmark' title='Social Media Information Propagation'>Social Media Information Propagation</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/tips/peertester-community-testing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Testing Sessions with Digest::SHA256 Passwords In Rails</title>
		<link>http://eric.lubow.org/2009/ruby/rails/testing-sessions-with-digestsha256-passwords-in-rails/</link>
		<comments>http://eric.lubow.org/2009/ruby/rails/testing-sessions-with-digestsha256-passwords-in-rails/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 06:00:31 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=233</guid>
		<description><![CDATA[I am fairly new to Rails, but from what I have learned thus far, its fantastic. I plan on posting more obscure Rails items as I come across them. I am writing an application that is similar in functionality to Yelp (in some ways). I have had some help along the way from a seasoned [...]]]></description>
			<content:encoded><![CDATA[<p>I am fairly new to Rails, but from what I have learned thus far, its fantastic.  I plan on posting more obscure Rails items as I come across them.</p>
<p>I am writing an application that is similar in functionality to <a href="http://www.yelp.com/">Yelp</a> (in some ways).  I have had some help along the way from a seasoned Rails vet. One of the things he helped me with was setting up the sessions_controller.  He did this in such a way that I wasn&#8217;t initially sure how to write the functional tests for it.  The sessions_controller contained code like this (it&#8217;s a bit more in depth than this, but this will give you the idea):</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> create<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@current_user</span> = User.<span style="color:#9900CC;">find_by_username</span><span style="color:#006600; font-weight:bold;">&#40;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:username</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@current_user</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#6666ff; font-weight:bold;">Digest::SHA256</span>.<span style="color:#9900CC;">hexdigest</span><span style="color:#006600; font-weight:bold;">&#40;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:password</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#0066ff; font-weight:bold;">@current_user</span>.<span style="color:#9900CC;">password</span> <span style="color:#006600; font-weight:bold;">&#41;</span> != <span style="color:#0066ff; font-weight:bold;">@current_user</span>.<span style="color:#9900CC;">password_salt</span><br />
&nbsp; &nbsp; &nbsp; redirect_to<span style="color:#006600; font-weight:bold;">&#40;</span> login_path <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; redirect_to<span style="color:#006600; font-weight:bold;">&#40;</span> user_path <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>So when it came time to write the functional tests for this (using fixtures), I couldn&#8217;t get away with just a <strong>user.yml</strong> like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">test_user:<br />
&nbsp; &nbsp; username: test_user<br />
&nbsp; &nbsp; password: secretuser<br />
&nbsp; &nbsp; firstname: General<br />
&nbsp; &nbsp; lastname: User<br />
&nbsp; &nbsp; email: test_user@user.com<br />
&nbsp; &nbsp; role: normal<br />
&nbsp; &nbsp; nickname: Mr. Testy</div></div>
<p>The reason for this is because the user table contains an extra column pertaining to the password called password_salt (which you&#8217;ll notice referenced above).  Therefore my user fixture needed to look something more like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">test_user:<br />
&nbsp; &nbsp; username: test_user<br />
&nbsp; &nbsp; password: A0Mrhnu4 &nbsp;# secretsalt<br />
&nbsp; &nbsp; password_salt: 868532ea243f03c2ce5f6f99dcf9e27342c39ce51819fa0605302ab4b5c3841e<br />
&nbsp; &nbsp; firstname: Test<br />
&nbsp; &nbsp; lastname: User<br />
&nbsp; &nbsp; email: test_user@example.com<br />
&nbsp; &nbsp; role: normal<br />
&nbsp; &nbsp; nickname: Mr. Testy</div></div>
<p>The other fixture still has it usefulness in testing (like testing logins that won&#8217;t work), so don&#8217;t get rid of it so quickly.</p>
<p>How do I generate that salt and the <em>hashed</em> password?  I&#8217;m glad you asked.  I&#8217;m sure there is a better way to do it than I did, but I just went into the application, created a user and then went into the console, grabbed the user information and copied it into the fixture.  Then I used the following code in my <strong>sessions_controller_test.rb</strong> for the functional test:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_should_logout_and_clear_session<br />
&nbsp; &nbsp; post <span style="color:#ff3333; font-weight:bold;">:destroy</span>, <span style="color:#ff3333; font-weight:bold;">:username</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'test_salt'</span>, <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'secretsalt'</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:return_to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/'</span><br />
&nbsp; &nbsp; assert_redirected_to <span style="color:#996600;">'/'</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></div>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/tips/peertester-community-testing/' rel='bookmark' title='Peertester Community Testing'>Peertester Community Testing</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/one-time-modal-windows-with-rails-and-fancybox/' rel='bookmark' title='One Time Modal Windows With Rails and Fancybox'>One Time Modal Windows With Rails and Fancybox</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/shortcut-notation-in-rails-callbacks/' rel='bookmark' title='Shortcut Notation in Rails Callbacks'>Shortcut Notation in Rails Callbacks</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2009/ruby/rails/testing-sessions-with-digestsha256-passwords-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

