<?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>Pivotal Labs &#187; Andrew Bruce</title>
	<atom:link href="http://pivotallabs.com/author/abruce/feed/" rel="self" type="application/rss+xml" />
	<link>http://pivotallabs.com</link>
	<description>Agility Developed</description>
	<lastBuildDate>Wed, 19 Jun 2013 22:16:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>The passing of time, and all of its crimes.</title>
		<link>http://pivotallabs.com/the-passing-of-time-and-all-of-its-crimes/</link>
		<comments>http://pivotallabs.com/the-passing-of-time-and-all-of-its-crimes/#comments</comments>
		<pubDate>Mon, 17 Jun 2013 00:08:05 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=20279</guid>
		<description><![CDATA[<p>Programmers are constantly implementing time-related features, and accidentally including time-related bugs. I&#8217;m one of those programmers, and I would like to reduce the number of time-related bugs that I write. Some of them are small mistakes: time zone issues arise when running a test suite on a machine in a different time zone. These bugs are often fixed with consistent use of the time zone feature of a given time library. Others are more sinister, and lurk deep within the design of a system. They manifest in places where it&#8217;s tricky to get the system into a certain state because it is so heavily dependent on the current time. I propose that designing for the ability to set the current time from the outside of the system reduces the prevalence of timing related bugs, and has the happy accident of making code more reusable and testable. How testing exposes this&#8230;</p><p>The post <a href="http://pivotallabs.com/the-passing-of-time-and-all-of-its-crimes/">The passing of time, and all of its crimes.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Programmers are constantly implementing time-related features, and accidentally including time-related bugs. I&#8217;m one of those programmers, and I would like to reduce the number of time-related bugs that I write. Some of them are small mistakes: time zone issues arise when running a test suite on a machine in a different time zone. These bugs are often fixed with consistent use of the time zone feature of a given time library. Others are more sinister, and lurk deep within the design of a system. They manifest in places where it&#8217;s tricky to get the system into a certain state because it is so heavily dependent on the current time. I propose that designing for the ability to set the current time from the outside of the system reduces the prevalence of timing related bugs, and has the happy accident of making code more reusable and testable.</p>
<h2>How testing exposes this problem</h2>
<p>Testing has many forms in the world of software. There are automated acceptance tests, unit tests, functional tests, enemy tests and so on. There are also tests carried out by humans. Sometimes referred to as &#8216;click testing&#8217; or Quality Assurance, this kind of testing is an essential part of the process of delivering working software. At Pivotal Labs, it&#8217;s usually the Product Manager who has the final say about whether a feature is complete, or a bug is fixed. In order to evaluate whether a feature is ready, the PM exercises the area of the application in question, using the interface that a customer or stakeholder has been provided with.</p>
<p>When testing software with a mouse and keyboard becomes difficult, however, it often doesn&#8217;t get done. When it doesn&#8217;t get done, bugs introduced by diligent programmers, who test-drive their code, are missed and end up making their way into production.</p>
<p>After a few cycles of missing bugs like this, a team will look for ways to ease the pain of click testing their app. The programmers on the team might come up with clever, easy-to-implement solutions to this problem:</p>
<ul>
<li>&#8220;We can manipulate the Time library to give us the time we want&#8221;</li>
<li>&#8220;We can change all of the data for a given account to pretend that it was created in the past&#8221;</li>
</ul>
<p>When these sorts of techniques dig in, new problems arise. In the former case, you can end up with code that works when the fake Time library is used, but not when the real one is used. In the latter, you are committed to a maintenance chore: when a timestamp field is added, it needs to change along with the rest, and when the code that changes those fields gets out of sync with how things really change over time, more bugs arise. It becomes difficult to tell which bugs are genuine and which are a consequence of artificially shifting time data.</p>
<p>It&#8217;s usually programmers who propose the above solutions. We often think in low-level terms like libraries and direct data manipulation. From a Product Manager&#8217;s perspective, however, what&#8217;s really needed is a design change. One could imagine the user story presented to the team like this:</p>
<p>As a Product Manager<br />
I want to travel in time<br />
So that I can test, for example, that an account gets billed each month</p>
<p>Time travel sounds like science fiction. How could a user of your system possibly travel in time? It turns out that there are low-level solutions to this. For example, Timecop, which <a href="https://github.com/travisjeffery/timecop/commit/6942d0eed940ea9a4e06d4dd9658f97bd7c14c8b">many</a> <a href="https://github.com/travisjeffery/timecop/commit/7c41d86343225ccb9ccf58701424674d9f0f851b">of</a> <a href="https://github.com/travisjeffery/timecop/commit/f105e15482fa2629693aee95d400c6428025b788">us</a> at Pivotal have contributed to. If depending on the passing of time is your addiction, then Timecop is enabling you. It lets you easily manipulate time, usually for automated testing purposes. For example:</p>
<pre>
<code class="language-ruby">Timecop.freeze(1.month.from_now) do
  future_time = Time.now
  sleep 10
  future_time == Time.now # this is true
end
</code>
</pre>
<p>Here we&#8217;ve frozen time to pretend that it&#8217;s one month in the future. I can imagine some cases where this would be useful (not least in existing systems that are infected with code coupled to the current time), but in a lot of cases this is just wrong. Under what circumstance do you actually expect your code to be frozen in time? What are the consequences of testing code under these conditions?</p>
<p>Perhaps most importantly to the topic of this post, Timecop lets you forget about managing time at the unit level, and doesn&#8217;t encourage you to build time controls into your application.</p>
<p>I think there are better ways to get a grip on time that we should all consider before reaching for the magic wand. Let&#8217;s look at some real-world problems that can occur and then look at ways of building time control into an app&#8217;s design.</p>
<h2>Examining the moment</h2>
<p>Let&#8217;s think about the properties of the current time:</p>
<ul>
<li>There is only one current time, unless you&#8217;re modelling multiple realities e.g. storylines about time travel.</li>
<li>Its value is always changing.</li>
<li>Everything is potentially affected by it.</li>
</ul>
<p>So, the current time is a global, constantly mutating singleton. We know that the presence of global singletons is undesirable, because they are polluting. We also know that mutation ought to be contained, because mutable state makes our programs less predictable and harder to reason about. If a function deals with mutable state, then it might have different results each time it is called, even when it apparently has the same inputs.</p>
<p>Let&#8217;s look at a timing bug that can result from the fact that the current time has these undesirable properties:</p>
<pre>
<code class="language-ruby">policy = Policy.find(1)

if policy.current_state == :active
  notify_customer("You are still insured!")
end
# more code goes here
if policy.current_state == :inactive
  notify_customer("You are not insured. Hope you weren't planning on driving anywhere today.")
end
</code>
</pre>
<p>Imagine that the above code is within a web request. The request comes in at a certain time, and the customer wants to know whether their insurance policy is current. The code above is deep in the guts of a model somewhere, and gets called after the customer has been authenticated, their request has been authorized, and their account record has been pulled out of the database. Now it&#8217;s time to see what the state of the policy is, so we use a method someone wrote (current_state) that fetches the current time and returns a state based on whether the policy&#8217;s end date was before or after that time.</p>
<p>The customer sees this on their screen:</p>
<pre>
You are still insured!
You are not insured. Hope you weren't planning on driving anywhere today.
</pre>
<p>The policy could potentially be active on one line and inactive the next. This kind of bug gets worse when one line makes an external call if the object were in one state, and the next makes a conflicting call if it were in another.</p>
<p>I recently ran into a real bug similar to this on my current project, which was caught when an acceptance test I was writing would fail on one run and pass on the next. The temporary workaround was to memoize the method that checked the current state (current_state above). Unfortunately, this introduced even more mutable state, because memoization requires changing the state of an instance variable. The next programmer might wonder why fetching the current state works the first time he asks, but stays the same with consecutive calls.</p>
<h2>current_nothing</h2>
<p>The current_state method is guilty here. But what of? It has a hidden input, which is the current time. It&#8217;s not explicit, and that&#8217;s where the confusion lies. It wouldn&#8217;t make sense to have a method called current_something and have it take the time as an argument, because the prefix &#8220;current_&#8221; implies that it&#8217;s supposed to know what the current state is.</p>
<p>The internal functions of a program shouldn&#8217;t know this stuff. In most web apps, a request is made at a certain point in time, but it&#8217;s not important that the request takes some time. With most scheduled jobs, the job is run at a certain time, but it&#8217;s not important that the job takes some time (or if it is, it&#8217;s stored as metadata).</p>
<p>A name less prone to attracting this kind of bug might be state_as_of(time). If we force ourselves to pass the time as a parameter to all of our low-level functions, then we can:</p>
<ol>
<li>More easily unit test the basic correctness of the method without resorting to stubbing out the time with Timecop.</li>
<li>Force out a decision to be made about what moment the lower-level methods should be operating on. Ideally the control would move as high as possible: to the controller level, or in the case of jobs, to the job itself, or to an environment variable.</li>
</ol>
<h2>A word about scheduling</h2>
<p>Scheduled jobs are often concerned with when they think they&#8217;re being run, but a PM doesn&#8217;t want to wait for a month to see if, for example, the billing system is working. It&#8217;s important to give control over when a job thinks it&#8217;s being run to the PM or other person evaluating whether a system works. This might mean dropping your out-of-the-box scheduling interface for the purposes of feature acceptance.</p>
<p><a href="https://github.com/bvandenbos/resque-scheduler">Resque-scheduler</a> has become very popular amongst developers as it&#8217;s easy to install and provides a cron-like syntax for declaring when jobs are run. It also provides a GUI for triggering scheduled jobs immediately. Unfortunately, there&#8217;s no way to set parameters for the jobs, so the time can&#8217;t be set. If you choose to heed the advice in this post and parameterize time, you&#8217;ll need to provide your own interface for passing the current time into the system. This is a good idea anyway. See <a href="http://growing-object-oriented-software.com/">GOOS</a> for a good treatment of externalizing event sources, which goes even further than the suggestions in this post in many ways.</p>
<p>Making time a parameter to your jobs can often make the jobs more reusable. For example, I might want to invalidate all sessions in a particular time range because there was a system fault at those times.</p>
<h2>A word about external dependencies</h2>
<p>What happens if your external dependencies are dependent on the current time? Well, you&#8217;re going to have problems with that no matter how much control you build into your system. I would argue that the services should be wrapped, and the wrappers should allow the time to be passed in to fake responses if necessary. The acceptance (as in story acceptance in Pivotal Tracker) of your system doesn&#8217;t have to depend on the state of the other systems.</p>
<h2>A word about customer-facing status pages</h2>
<p>What if your customer needs to be shown what&#8217;s happening right now?<br />
I think the trick here is to depend on the order of time, and not the passing of time. To move into the future, we should be reacting to events by adding data, not mutating it. A database can easily figure out what the latest order is, or what the latest billing cycle is. It doesn&#8217;t have to be a function of the current time.</p>
<p>If, however, it&#8217;s just too difficult to implement the functionality without checking the current time, it could be argued that the current time be a parameter passed in through the browser, available only in certain testing environments. I would resist this as far as possible, but think that it would be a preferable solution to mutating the state of the database.</p>
<p>The post <a href="http://pivotallabs.com/the-passing-of-time-and-all-of-its-crimes/">The passing of time, and all of its crimes.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/the-passing-of-time-and-all-of-its-crimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ll come running back to GNU</title>
		<link>http://pivotallabs.com/ill-come-running-back-to-gnu/</link>
		<comments>http://pivotallabs.com/ill-come-running-back-to-gnu/#comments</comments>
		<pubDate>Sun, 09 Jun 2013 20:09:08 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=20106</guid>
		<description><![CDATA[<p>I&#8217;d finally had enough of waiting for my MacBook Pro&#8217;s hard drive platter to spin up and grind away, so I ordered a new Solid State Drive. When it arrived, I was faced with the potentially drawn-out process of setting up a new OSX installation, which might have involved proving I owned a copy of Lion or whatever beast I currently had installed. Alternatively, I could have cloned my old disk, but I&#8217;d heard that was sometimes problematic, and the fresh disk felt like an opportunity to wipe the slate clean. I chose what I thought must by now be a path of less resistance for many developers: installing Linux instead. This wasn&#8217;t a wild jump into the unknown: I had run various flavours of GNU/Linux since I was a teenager, eventually settling on Ubuntu. I bought a dedicated Ubuntu laptop from Dell when they came out, but caved and&#8230;</p><p>The post <a href="http://pivotallabs.com/ill-come-running-back-to-gnu/">I&#8217;ll come running back to GNU</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;d finally had enough of waiting for my MacBook Pro&#8217;s hard drive platter to spin up and grind away, so I ordered a new Solid State Drive. When it arrived, I was faced with the potentially drawn-out process of setting up a new OSX installation, which might have involved proving I owned a copy of Lion or whatever beast I currently had installed. Alternatively, I could have cloned my old disk, but I&#8217;d heard that was sometimes problematic, and the fresh disk felt like an opportunity to wipe the slate clean. I chose what I thought must by now be a path of less resistance for many developers: installing Linux instead.</p>
<p>This wasn&#8217;t a wild jump into the unknown: I had run <a href="http://www.gentoo.org/">various</a> <a href="http://fedoraproject.org/">flavours</a> <a href="http://www.debian.org/">of</a> <a href="http://www.slackware.com/">GNU/Linux</a> since I was a teenager, eventually settling on <a href="http://www.ubuntu.com/">Ubuntu</a>. I bought a dedicated Ubuntu laptop from Dell when they came out, but caved and bought this MacBook Pro when I could afford it, around 2008. Persuading myself that I needed to run Photoshop for my fledgling freelance career, it struck a good balance between the benefits of the open-source community and the plug-n-play reliability of a popular commercial OS. Development on OSX is pretty easy these days, but there are still some weird issues. Installing Ruby on OSX was non-trivial last time I tried, <a href="https://github.com/mxcl/homebrew">homebrew</a> eases some dependency installation pain but introduces its own set of maintenance chores, and Xcode is a bit of a dog to keep up to date.</p>
<p>There&#8217;s some conventional thinking in the Linux desktop world that says old hardware has a better chance of working. The MacBook Pro 5,5 that I have is a recognisable set of venerable components (&#8220;sudo dmidecode -s system-product-name&#8221; gives you the version of the Mac hardware you are running). However, the latest Ubuntu 13.04 sets things up so that I:</p>
<ol>
<li>Am greeted with a corrupted boot screen each time I start the computer</li>
<li>Can turn my machine into a brick by simply closing the lid</li>
<li><a href="https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1170958">See a long horizontal shadow at the top of full-screen videos</a></li>
<li>Am regularly thrown into a different app when I use two-finger scrolling</li>
</ol>
<p>Granted, this is a far cry from, &#8220;my wifi and sound took three weeks to set up and still didn&#8217;t work well&#8221;, but it&#8217;s hardly the smooth experience that Mac users are used to. Here are the fixes.</p>
<h2>Corrupted boot screen</h2>
<p>Use proprietary nvidia drivers. These work better, but you&#8217;re then stuck with a permabright, battery-sucking screen because the keyboard brightness controls don&#8217;t work. This can be fixed by <a href="http://askubuntu.com/questions/83965/ubuntu-10-04-cant-adjust-brightness-on-my-lenovo-thinkpad/199650#199650">getting your hands dirty in a config file</a> (note the older version of Ubuntu this was solved for). Not awesome.</p>
<h2>Brick state</h2>
<p>This happens because a lid close defaults to suspend, and suspend breaks the open source nvidia drivers. A reboot doesn&#8217;t seem to fix it. Kudos for getting so far with reverse engineering, but I wasn&#8217;t prompted with an option to choose the proprietary drivers. I&#8217;d rather check a box that says &#8220;non-free software that works&#8221; over &#8220;free software that ruins your day&#8221;. This prompt used to be present on previous versions of Ubuntu.</p>
<p>You can sometimes recover from the brick state by moving to a regular non-X console (ctrl+alt F1) and killing lightdm with sudo. Otherwise, you&#8217;re in boot-from-CD land. How many non-technical types do you know who can / would want to work that out?</p>
<h2>Horizontal shadow of panel when running videos full-screen</h2>
<p>This one is interesting. The Ubuntu team knew about the problem, but shipped anyway. I can sympathise with the difficulties of maintaining a dual server and desktop OS, and with sticking to a deadline, but if the 80% case could have been solved by loading Workspace Switcher by default, why not do that?</p>
<h2>Two-finger scrolling occasionally throws you into another app</h2>
<p>This happens because Unity has hardcoded gesture support for touchpads. Three finger double-tap means &#8216;take me to the previous window&#8217;, and three finger tap then tap-and-hold means &#8216;open a super-sensitive window switcher that I control with the mouse&#8217;. I never want to change windows with the mouse.</p>
<p>There are several solutions to this problem floating around, but they all involve modifying the Unity source code and recompiling. This is crazy. Please make gestures optional!</p>
<h2>In summary</h2>
<p>I had previous experience with dealing with this category of problems, but someone who isn&#8217;t a full-time computer nerd might not have so much fun dealing with these bugs. Many of them seem to be reflective of Ubuntu&#8217;s confused attitude towards free software. The OS seems to push free drivers onto the user, but they aren&#8217;t always ready for prime time. Are end-users being used as testers?</p>
<p>Perhaps I&#8217;ll give it a few weeks before I cave and reinstall OSX. Most of the creases are ironed out now, but if I have to spend another few hours googling for solutions to mindless bugs, I may just give in to temptation again. YMMV.</p>
<p>The post <a href="http://pivotallabs.com/ill-come-running-back-to-gnu/">I&#8217;ll come running back to GNU</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/ill-come-running-back-to-gnu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Admin for nothin&#8217;, design for free.</title>
		<link>http://pivotallabs.com/admin-for-nothin-design-for-free/</link>
		<comments>http://pivotallabs.com/admin-for-nothin-design-for-free/#comments</comments>
		<pubDate>Sat, 01 Jun 2013 21:04:02 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[greek tragedy]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=19740</guid>
		<description><![CDATA[<p>This week&#8217;s blog post contains scenes from the ancient Greek tragedy Oikonomia, previously thought to be lost. It begins with a dance. In the dance, the product manager is conducting an iteration planning meeting with his developers (or LOLDEVs in the ancient tongue). The product owner, YOLOPO, makes an appearance towards the end. She wants a new feature. The drama proceeds: Act I, Scene I YOLOPO: The gods have decided that we will send out emails when people haven&#8217;t interacted with our service for a while. We&#8217;d better make it happen. ROFLPM: OK we can totally do that. I&#8217;ll write a story for it. Act I, Scene II ROFLPM: So, we&#8217;ve been discussing this story for a while now. We probably need some control over the various factors involved. What do you loldevs think? LOLDEV: An automatic admin interface is easy to install. It Just Works™. Add a line to&#8230;</p><p>The post <a href="http://pivotallabs.com/admin-for-nothin-design-for-free/">Admin for nothin&#8217;, design for free.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This week&#8217;s blog post contains scenes from the ancient Greek tragedy <em>Oikonomia</em>, previously thought to be lost. <a href="http://www.english.emory.edu/DRAMA/medea.mov">It begins with a dance</a>. In the dance, the product manager is conducting an iteration planning meeting with his developers (or LOLDEVs in the ancient tongue). The product owner, YOLOPO, makes an appearance towards the end. She wants a new feature. The drama proceeds:</p>
<h2>Act I, Scene I</h2>
<p>YOLOPO: The gods have decided that we will send out emails when people haven&#8217;t interacted with our service for a while. We&#8217;d better make it happen.</p>
<p>ROFLPM: OK we can totally do that. I&#8217;ll write a story for it.</p>
<h2>Act I, Scene II</h2>
<p>ROFLPM: So, we&#8217;ve been discussing this story for a while now. We probably need some control over the various factors involved. What do you loldevs think?</p>
<p>LOLDEV: An automatic admin interface is easy to install. It Just Works™. Add a line to your Gemfile and you&#8217;re done! Who has the time to write all those repetitive screens anyway?</p>
<p>ROFLPM: Perfect! Now anyone with access to the admin interface has direct access to those models you&#8217;ve been writing that do all the work! Rails developers bring so much free stuff.</p>
<p>LOLDEV: Never mind all that. How should we break down this enormous story?</p>
<p>ROFLPM: Well, it&#8217;s a biggie, and you loldevs are going to spend too much time away from master before we see any progress, so we&#8217;d better break it into three:</p>
<ol>
<li>the first story is about an admin user being able to change a time limit in the automatic admin interface</li>
<li>the second story has a customer using the system, and then not using it for the configured amount of time from the first story, and an administrator expecting a value to appear in the automatic admin interface when that time is up</li>
<li>the third story has an administrator changing the aforementioned value in the automatic admin interface and a user receiving an email</li>
</ol>
<p>LOLDEV: Great! That means we can do as YOLOPO wants and parallelize our team to build stuff faster. One pair of loldevs can add the time out setting, another pair can work on getting the value to appear in the automatic admin interface, and yet another pair can work on dispatching the email.</p>
<h2>Act II, Scene II</h2>
<p>LOLDEV1: Phew! We finally finished that set of stories. It&#8217;s a shame we had so many integration problems, but at least it&#8217;s done now. Plus, the admin interface is so easy to use that YOLOPO can mess around with it all she likes.</p>
<p>LOLDEV2: Yeah I heard she really likes being able to see all the data and play around with different things.</p>
<p>LOLDEV3: Hmm, there&#8217;s something I don&#8217;t like about that, but I can&#8217;t put my finger on it.</p>
<p>LOLDEV1: What?</p>
<h2>Act III, Scene IV</h2>
<p>ROFLPM: Hey, remember that feature about sending emails to users when their accounts  haven&#8217;t been used for an arbitrary amount of time? Well, YOLOPO says it doesn&#8217;t work anymore.</p>
<p>LOLDEV: Oh, I think YOLOPO will find that it does.</p>
<p>ROFLPM: Nah-ah! I changed the send_email_soon attribute to true and nothing happened!</p>
<p>LOLDEV: You&#8217;re not still using that old thing? We moved email sending to the controllers because we were randomly sending emails to people with active accounts and our test suite was slow and&#8230;</p>
<p>ROFLPM: Oh, OK then what do I do now?</p>
<p>LOLDEV: You have to sign up and then pretend it&#8217;s the future.</p>
<p>ROFLPM: How do I do that?</p>
<p>LOLDEV: Well, there&#8217;s an attribute on every user that you can change in the admin interface.</p>
<p>ROFLPM: Perfect!</p>
<p>The post <a href="http://pivotallabs.com/admin-for-nothin-design-for-free/">Admin for nothin&#8217;, design for free.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/admin-for-nothin-design-for-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.english.emory.edu/DRAMA/medea.mov" length="2706881" type="video/quicktime" />
		</item>
		<item>
		<title>Everything I know about Clojure after one week</title>
		<link>http://pivotallabs.com/everything-i-know-about-clojure-1-week/</link>
		<comments>http://pivotallabs.com/everything-i-know-about-clojure-1-week/#comments</comments>
		<pubDate>Sun, 26 May 2013 03:34:21 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=19556</guid>
		<description><![CDATA[<p>This week I decided to clear out the cobwebs of my Ruby-trained brain and try a completely different language. Ruby and Rails have been my staples for over seven years, and I&#8217;m starting to tire of my patterns of thinking, and of the common problems found in large Rails applications. Specifically, I&#8217;m pretty bored of running into slow test suites and difficult-to-maintain apps. I suspect the primary cause of these problems is the entanglement of business logic with database and other stateful resource code. I get the feeling that it can&#8217;t be just coincidence that so many teams of competent developers fall into the same old traps. I&#8217;d heard a bit about Clojure, so decided to explore the ecosystem and community. I&#8217;m attracted to the idea of learning a functional language, avoiding mutable state and re-evaluating the object oriented programming paradigm. Functional programmers are often accused of being &#8220;idealistic&#8221;, &#8220;academic&#8221;&#8230;</p><p>The post <a href="http://pivotallabs.com/everything-i-know-about-clojure-1-week/">Everything I know about Clojure after one week</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This week I decided to clear out the cobwebs of my Ruby-trained brain and try a completely different language. Ruby and Rails have been my staples for over seven years, and I&#8217;m starting to tire of my patterns of thinking, and of the common problems found in large Rails applications. Specifically, I&#8217;m pretty bored of running into slow test suites and difficult-to-maintain apps. I suspect the primary cause of these problems is the entanglement of business logic with database and other stateful resource code. I get the feeling that it can&#8217;t be <em>just</em> coincidence that so many teams of competent developers fall into the same old traps.</p>
<p>I&#8217;d heard a bit about <a href="http://clojure.org/">Clojure</a>, so decided to explore the ecosystem and community. I&#8217;m attracted to the idea of learning a functional language, avoiding mutable state and re-evaluating the object oriented programming paradigm. Functional programmers are often accused of being &#8220;idealistic&#8221;, &#8220;academic&#8221; or a variety of other thinly-veiled primitive insults. If nothing else, I could learn to sympathise with these crackpot underdogs who claim to have the cure for most of the technical pain I suffer in my chosen occupation.</p>
<p>Hopefully this assortment of links and lessons learned will encourage you to try out the language, or inspire you to try something else that&#8217;s refreshingly new.</p>
<h2>Clojure is easy to get started with</h2>
<p>There are various tutorials online. However, they can be a little out of date. The quickest route to Clojure hacking is via <a href="https://github.com/technomancy/leiningen">leiningen</a>, a sort of rake-meets-bundler utility. Assuming you&#8217;re on a Mac, have <a href="http://mxcl.github.io/homebrew/">homebrew</a> installed, a recent JDK and the usual code compilation dependencies:</p>
<pre><code class="language-bash">brew install leiningen
lein repl
</code></pre>
<p>That&#8217;ll pull in Clojure for you. Once you&#8217;ve had a play in the REPL, use leiningen to generate an app:</p>
<pre><code class="language-bash">lein new my-test-project</code></pre>
<p>The project.clj that the above command generates is the equivalent of a gemspec, and declares the dependencies of your app. Leiningen helpfully fetches dependencies lazily when you start a repl, server or run tests. No bundle install step!</p>
<p>Homebrew can also install Clojure for you, but this version will be independent of leiningen apps. When you install it, you&#8217;ll be recommended to use a REPL wrapper for rlwrap. I&#8217;ve found that the <a href="http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started">one from the wikibooks site</a> works better (i.e. at all).</p>
<h2>Rich Hickey is an entertaining figurehead</h2>
<p>Rich Hickey, creator of Clojure and designer of Datomic, the FP-friendly database system everyone&#8217;s talking about, has some <a href="http://www.infoq.com/author/Rich-Hickey">inspiring talks</a> from the end of last year about Clojure and Datomic, and notably why everybody is doing programming wrong. There are some pretty strong views in the talks, but they&#8217;re a refreshing take on the sociological patterns in our industry, and how project pathologies can be treated. </p>
<h2>There&#8217;s an active community</h2>
<p>Many clojure developers are ex- or current-Rubyists. For example, Jay Fields maintains the <a href="https://github.com/jaycfields/expectations">expectations testing library</a> (more on this below).</p>
<p>Clojure has artsy cred, too: there are several videos on the web showing Clojure being used for <a href="http://vimeo.com/46867490">live music</a>. </p>
<h2>Syntax change requires healthy brain re-wiring and thought simplification</h2>
<p>After spending so much time wrapping my head around object-oriented constructs and trying to work out how best to structure OO programs, it&#8217;s a refreshing change to work with a functional language. Not having a CS degree, I&#8217;d previously tinkered with Scheme following a <a href="http://www.ccs.neu.edu/home/matthias/BTLS/">workbook</a>. I wasn&#8217;t put off by parentheses, but did have some fears that I&#8217;d be transported back to the bad old days of the top-level PHP namespace. I soon realised, however, that my beef with PHP was mainly the aforementioned comingling of state and logic, as well as the inconsistencies of method signatures and names.</p>
<p>Clojure philosophy is all about consistency and reuse. I&#8217;ve trained myself to believe that reuse is all about identifying concepts, naming them and adding an abstraction, often a named value object. I&#8217;m pretty attached to my explicitly named classes of values, like SubscriptionEvent or <a href="http://joelneely.wordpress.com/2010/03/10/why-lists-are-not-primitive/">PersonName</a>. This is largely in reaction to the recognisable OO smells like Primitive Obsession. The problems inherent in such smells generally melt away in the FP world, since you&#8217;re encouraged to use the built-in types to provide equality and the like, and to use the common functions like map, reduce and so forth to achieve what you would do in OO with a value object&#8217;s methods.</p>
<h2>Web development is potentially full-stack</h2>
<p>This is worth knowing if you don&#8217;t already: Clojure already compiles to JavaScript in the browser, as well as to Java on the server. So we potentially could be doing single-language full-stack development like node.js but without the <a href="http://bonsaiden.github.io/JavaScript-Garden/">oft-cited pitfalls of JavaScript</a>. An excellent resource for newcomers to Clojure is this <a href="http://himera.herokuapp.com/synonym.html">translation between JS and Clojure</a>.</p>
<p>I&#8217;ve begun a project for playing around with the <a href="https://github.com/weavejester/compojure">Compojure</a> web routing library. Compojure forms the basis of many Clojure web apps, and I&#8217;m using that repository as a place to stick my learnings. I&#8217;m test-driving each new feature, so that it might serve as a reference for other newcomers on how to do TDD for Clojure web apps.</p>
<h2>TDD is easy, fast and totally not banned.</h2>
<p>Watching the Hickey talks, you might come away with the impression that the Clojure community is anti-TDD. However, there are some excellent developments going on in this area, such as the aforementioned Jay Fields&#8217; expectations library, which provides an achingly simple way to express intent in tests. See <a href="https://github.com/camelpunch/compojureref/blob/master/test/pages_test.clj">my first attempts at testing a web app</a> for an example of this. Structural whitespace optional.</p>
<h2>Monads still a mystery</h2>
<p>One week just wasn&#8217;t enough. See if you can <a href="http://www.intensivesystems.net/tutorials/monads_101.html">figure it out</a> and send me a postcard with a succinct summary.</p>
<p>Until next time!</p>
<p>The post <a href="http://pivotallabs.com/everything-i-know-about-clojure-1-week/">Everything I know about Clojure after one week</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/everything-i-know-about-clojure-1-week/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Designing an API in Hell</title>
		<link>http://pivotallabs.com/designing-an-api-in-hell/</link>
		<comments>http://pivotallabs.com/designing-an-api-in-hell/#comments</comments>
		<pubDate>Sun, 19 May 2013 18:16:18 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[minitest]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=19329</guid>
		<description><![CDATA[<p>Minitest, Ruby&#8217;s built-in testing library, has some great out-of-the-box features. One of these is test parallelization. Parallel testing is often added after a suite gets slow enough to hurt. That can be achieved using the parallel_tests gem, which takes advantage of today&#8217;s multi-core processors, or using custom solutions for dividing chunks of a suite across several machines. Arguably, test speed should be dealt with by making code design changes, but that&#8217;s another story: what interests me most about minitest&#8217;s parallelization is the constraints it places upon the design of stateful systems when TDDing from scratch. You can turn on parallelization for a particular test case: describe Server do parallelize_me! end or for all tests: require 'minitest/hell' As the name implies, the latter approach turns up the test pain level to 11, but it&#8217;s the kind of pain that can have positive effects. For &#8216;fun&#8217;, I started to use minitest&#8217;s parallelization&#8230;</p><p>The post <a href="http://pivotallabs.com/designing-an-api-in-hell/">Designing an API in Hell</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/seattlerb/minitest">Minitest</a>, Ruby&#8217;s built-in testing library, has some great out-of-the-box features. One of these is <a href="http://blog.zenspider.com/blog/2012/12/minitest-parallelization-and-you.html">test parallelization</a>. Parallel testing is often added after a suite gets slow enough to hurt. That can be achieved using the <a href="https://github.com/grosser/parallel_tests">parallel_tests gem</a>, which takes advantage of today&#8217;s multi-core processors, or using custom solutions for dividing chunks of a suite across several machines. Arguably, test speed should be dealt with by making code design changes, but that&#8217;s another story: what interests me most about minitest&#8217;s parallelization is the constraints it places upon the design of stateful systems when TDDing from scratch.</p>
<p>You can turn on parallelization for a particular test case:</p>
<pre><code class="language-ruby">describe Server do
  parallelize_me!
end
</code></pre>
<p>or for all tests:</p>
<pre><code>require 'minitest/hell'
</code></pre>
<p>As the name implies, the latter approach turns up the test pain level to 11, but it&#8217;s the kind of pain that can have positive effects. For &#8216;fun&#8217;, I started to use minitest&#8217;s parallelization on <a href="https://github.com/camelpunch/plumb">a side project</a>, which has a stateful API backed by a relational database. Here are some of the decisions that were forced out by using parallel test examples.</p>
<h2>Commitment to fast tests</h2>
<p>I thought that running tests in parallel from the start of a project would make me lazy, causing me to neglect slow tests because they&#8217;d be running at the same time as others. Surprisingly, the opposite happened: the need to constantly rerun the whole suite to iron out nondeterministic conflicts encouraged me to fix slow tests early. I ended up being able to run the entire suite several times within a matter of seconds in order to check the tests&#8217; ability to run in parallel.</p>
<p>Side note: this is an early-stage project, with a very low quantity of tests! It will be interesting to see how test speed increases as the volume of tests increases.</p>
<h2>Avoiding test duplication</h2>
<p>Since the unique constraints of my database could be hit by tests with the same fixture data running at the same time, I was encouraged to use more intention revealing test data for each example, avoiding foo and bar, which commonly litter a suite and make tests harder to read.</p>
<p>For IDs, I used Ruby&#8217;s <a href="http://rubydoc.info/stdlib/securerandom/SecureRandom">SecureRandom</a> library, which provides GUID and hex generation. I sometimes used hex generation when the user-supplied unique display name of something didn&#8217;t matter to the test.</p>
<h2>Client-side ID generation</h2>
<p>Although not strictly forced out from parallel tests, parallel testing got me thinking about how best to interact with the backend, which has a single database being served by multiple concurrent requests (just like any web server).</p>
<p>Using GUIDs instead of autoincrementing IDs can be a smart decision to make if you can (i.e. you don&#8217;t need human-friendly URLs), because it means your database server doesn&#8217;t need to worry as much about ensuring uniqueness, since the GUID algorithm <a href="http://stackoverflow.com/questions/2977593/is-it-safe-to-assume-a-guid-will-always-be-unique#answer-2977648">effectively guarantees it</a>.</p>
<p>TDDing my API from scratch, without external requirements, encouraged me to use GUIDs to simplify the design and to avoid bottlenecks at the database layer. POST requests canonically return the new URL of the resource you&#8217;re creating in the Location header of the response. So to test that a thing really got persisted I&#8217;d need to:</p>
<ol>
<li>POST to /items with a representation of the resource</li>
<li>Grab the Location header of the response to get the new URL</li>
<li>GET /items/:newid and ensure the response body matched the representation I sent</li>
</ol>
<p>This seemed a very laborious process for storing some data. Much less work is:</p>
<ol>
<li>PUT to /items/:newid</li>
<li>GET /items/:newid and ensure the response body matched the representation I sent</li>
</ol>
<p>Since GUIDs can be treated as unique, it didn&#8217;t make much sense for the server to generate them.</p>
<p>Positive effect: the app would now cope with a distributed database system on the back-end, despite starting out on a technology that&#8217;s thought of as difficult to scale horizontally (SQLite).</p>
<h2>Avoiding database resets</h2>
<p>It&#8217;s common practice to wipe the whole database when starting a new example, or to run each example in a transaction and roll it back when each example finishes. I wanted real black-box tests, so I didn&#8217;t want to use transactions. Yet, deleting the whole database at the start of an example didn&#8217;t play nice with minitest&#8217;s parallelization, since data that one example required would be deleted by another.</p>
<p>The usual approach when using parallel_tests is to create a database for each process. However, since minitest doesn&#8217;t manage databases (nor should it) I chose to keep a single database and find a different solution.</p>
<p>I chose to sandbox all of the tests by creating new entities each time, and only checking for output that indicated that particular entity had been worked on. The <a href="https://github.com/camelpunch/plumb">product I&#8217;m working on</a> is a Continuous Integration server, so I&#8217;d be creating CI projects (you might also know them as jobs) and expecting them to appear in an XML feed. The tests had to be OK with other data being present, since the other tests could be working too.</p>
<p>This approach precluded tests that checked that the number of records had increased by one, because in an otherwise acceptable &#8220;green&#8221; test situation they&#8217;d occasionally increase by more than one (another test added a record too), stay the same (another test deleted a record) or decrease (more than one had been deleted).</p>
<h2>Constraints are fun</h2>
<p>While I wouldn&#8217;t recommend going rogue like this on a client project, playing with constraints like truly parallel tests can get you thinking about your normal testing procedure. Some of the above decisions allowed for a much faster test execution time, and always having the assumption that other processes could be working on the database forced out some interesting techniques. Some of the techniques I had to avoid due to parallelization would normally necessitate different workarounds with their own drawbacks. For example, if you always assume the count of an ActiveRecord class will go up, you require exclusive use of the database. If instead you scope your queries to a parent entity, this restriction would be removed.</p>
<p>Hell isn&#8217;t so bad after all.</p>
<p>The post <a href="http://pivotallabs.com/designing-an-api-in-hell/">Designing an API in Hell</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/designing-an-api-in-hell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Smelling with your ears: TDD techniques to influence your design</title>
		<link>http://pivotallabs.com/smelling-with-ears-tdd-influence-design/</link>
		<comments>http://pivotallabs.com/smelling-with-ears-tdd-influence-design/#comments</comments>
		<pubDate>Mon, 13 May 2013 01:08:52 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[smells]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=18971</guid>
		<description><![CDATA[<p>Test Driven Development can be a hard sell. The first pitch is often designed to entice the buyer with safety features, like: &#8220;How will you ensure that those bugs don&#8217;t creep back in?&#8221; &#8220;Wouldn&#8217;t it be nice to know that one change doesn&#8217;t break another?&#8221; In conversations between practiced test drivers, though, design topics tend to pop up: &#8220;What is this test telling us about the design of our code?&#8221; &#8220;Why is this test boring to write?&#8221; &#8220;Why is this test so slow?&#8221; Then there are really exciting questions, when getting close to a design breakthrough, like: &#8220;Is this test telling us we&#8217;re lacking polymorphism in our design?&#8221; &#8220;I&#8217;m tired of constructing this thing. How can we group this set of arguments into an object with a name?&#8221; One distinguishing factor between these types of questions is the level of trust in TDD. Someone with little trust might be predisposed&#8230;</p><p>The post <a href="http://pivotallabs.com/smelling-with-ears-tdd-influence-design/">Smelling with your ears: TDD techniques to influence your design</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Test Driven Development can be a hard sell. The first pitch is often designed to entice the buyer with safety features, like:</p>
<ul>
<li>&#8220;How will you ensure that those bugs don&#8217;t creep back in?&#8221;</li>
<li>&#8220;Wouldn&#8217;t it be nice to know that one change doesn&#8217;t break another?&#8221;</li>
</ul>
<p>In conversations between practiced test drivers, though, design topics tend to pop up:</p>
<ul>
<li>&#8220;What is this test telling us about the design of our code?&#8221;</li>
<li>&#8220;Why is this test boring to write?&#8221;</li>
<li>&#8220;Why is this test so slow?&#8221;</li>
</ul>
<p>Then there are really exciting questions, when getting close to a design breakthrough, like:</p>
<ul>
<li>&#8220;Is this test telling us we&#8217;re lacking polymorphism in our design?&#8221;</li>
<li>&#8220;I&#8217;m tired of constructing this thing. How can we group this set of arguments into an object with a name?&#8221;</li>
</ul>
<p>One distinguishing factor between these types of questions is the level of trust in TDD. Someone with little trust might be predisposed to abandon testing before implementation, instead choosing to test afterwards, or not at all. To such a person yet to be sold on the benefits of TDD, the safety questions make more immediate sense, while design questions are often met with blank stares. However, the safety concerns are easily brushed off: it&#8217;s a prototype. My team is so smart we don&#8217;t need tests. We need to move fast, so we&#8217;ll worry about tests later.</p>
<p>Explaining the basic advantages of TDD doesn&#8217;t always work as a sales pitch, because those explanations don&#8217;t reveal why testing can be difficult, much less why testing sometimes <em>ought</em> to be difficult. Take someone who has never let the design of their code be influenced by tests: they dislike testing for being difficult or boring. Encountering resistance in the TDD process, they choose to forgo the safety advantages of testing, and the design advantages haven&#8217;t been made clear. </p>
<p>As you may have gathered, I&#8217;m more excited by the design aspect of TDD and related tools than by the safety aspect. I&#8217;d like to think that if we sold how TDD can improve the design of code that&#8217;s yet to be written, we&#8217;d have an easier time tricking our friends into writing code with regression protection.</p>
<h2>Learning to listen</h2>
<p>There is much talk about &#8220;listening to the tests&#8221; among TDD practitioners. The listening analogy is apt. Like listening with our ears, the ability to understand what a test tells us about code quality can improve with practice. It&#8217;s a subtle concept to grasp, and one I frequently find is not well understood by otherwise experienced developers. This is unfortunate, because it&#8217;s a crucial part of getting rapid feedback on the quality of production code. By quality, I&#8217;m referring primarily to the ability to cope with changing requirements, as opposed to good coverage of features and edge-cases. </p>
<p>If you can&#8217;t hear what your tests are trying to say, there are tools for cranking up the volume. Below are a couple of my favorites. They&#8217;re not intended as hard-and-fast rules, but as exercises to try out when you&#8217;re frustrated with a test or wondering why it&#8217;s getting difficult to test something. </p>
<p>If you haven&#8217;t already, you should read about <a href="http://xunitpatterns.com/Test%20Smells.html">known test smells and their solutions</a>, because we can apparently smell with our TDD ears. </p>
<h2>Use your testing framework&#8217;s convenience helpers sparingly</h2>
<p>In the RSpec world, this often comes down to writing readable examples without using &#8216;subject&#8217;, &#8216;let&#8217; or &#8216;before&#8217;. It turns out that straightforward assignment is usually OK.</p>
<p>As <a href="http://robots.thoughtbot.com/post/34709581001/lets-not">this Thoughtbot post</a> argues, the let helper effectively introduces Mystery Guests (implicit, hidden fixtures), and overuse results in slow and fragile tests.</p>
<p>I like to avoid lets, subjects and other test helpers for another reason: if I can&#8217;t stand to repeat myself in examples, I think about how the code that uses my code will feel. A boring, repetitive test setup might be telling me that my code has too many dependencies. If I&#8217;m frantically stuffing things into the database and stubbing out web service requests just to allow myself to construct an object, perhaps the object&#8217;s scope is too broad.</p>
<p>If you come across a test that is apparently repetitive, consider tidying the implementation of the system under test before the test itself. You may find that the noise in the test can be dramatically reduced with some production code tweaks.</p>
<h2>Avoid stubbing methods to return values</h2>
<p>I owe this one to <a href="http://gmoeck.github.io/">Greg Moeck</a>, who introduced something like it at the <a href="http://www.meetup.com/pivotal-labs-sf/">San Francisco eXtreme Tuesday Club</a>.</p>
<p>First, a reminder of the definition of stubs versus mocks (to paraphrase Gerard Meszaros):</p>
<ol>
<li>A stub is a test double that allows you to control the indirect inputs of the system under test.</li>
<li>A mock is a test double that allows you to test the indirect outputs of the system under test.</li>
</ol>
<p>If you return a value from a stubbed method, you force your production code to depend on a blocking, synchronous call. If you could otherwise send a message and not expect an immediate response, you permit your design to (now or in the future) be asynchronous.</p>
<p>Further to that, if you instead use a mock to expect an output to the collaborator you were previously stubbing, you can more cleanly divide your testing into inputs and outputs of the system under test. It&#8217;s the difference between:</p>
<pre><code class="language-ruby">it "ensures user is authentic before performing the action" do
  user = stub('user')
  authenticator = stub('authenticator')
  authenticator.stub(:authentic_user?).with(user) { true }
  action = Action.new(user)
  action.perform
  expect(action).to be_complete
end
</code></pre>
<p>and:</p>
<pre><code class="language-ruby">it "ensures the user is authentic when action is requested" do
  user = stub('user')
  authenticator = mock('authenticator') # assume the player of this role knows who to tell when authentication succeeds or fails
  authenticator.should_receive(:authenticate_user).with(user)
  action = Action.new(user)
  action.perform
end

it "performs an action once a user has been authenticated" do
  action = Action.new(stub('unauthenticated user'))
  authenticated_user = stub('user')
  action.user_successfully_authenticated(user)
  expect(action).to be_complete
end
</code></pre>
<p>The code that passes the second set of examples is in better shape for when you need to queue requests to the authenticator and complete the action asynchronously. It uses a <a href="http://pragprog.com/articles/tell-dont-ask">&#8220;tell, don&#8217;t ask&#8221;</a> style. The fact that an explicit message is sent to the system under test (&#8216;user_successfully_authenticated&#8217;) makes it clear to the reader that the request for authentication and the triggering of the action are separate bits of work. It&#8217;s someone else&#8217;s business whether I get told about the successful authentication, and how many steps are taken before I&#8217;m told.</p>
<p>There are several more techniques I&#8217;d like to tell you about, but this post is getting a bit long in the tooth. Maybe next time. Happy listening!</p>
<p>The post <a href="http://pivotallabs.com/smelling-with-ears-tdd-influence-design/">Smelling with your ears: TDD techniques to influence your design</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/smelling-with-ears-tdd-influence-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Procrastination, considered.</title>
		<link>http://pivotallabs.com/procrastination-considered-side-pet-project-soloing-versus-pairing/</link>
		<comments>http://pivotallabs.com/procrastination-considered-side-pet-project-soloing-versus-pairing/#comments</comments>
		<pubDate>Sun, 05 May 2013 21:04:16 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[pair programming]]></category>
		<category><![CDATA[pairing]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[soloing]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=18765</guid>
		<description><![CDATA[<p>Last week I blogged about a new project for aiding in the hunt for test pollution, Scrubber. This is a personal side project that I began recently. It&#8217;s in the very early stages, like many of my other pet projects. It&#8217;s something I&#8217;ve worked on entirely alone, though I&#8217;d also love to collaborate with others and/or pair on it. I was going to blog this week about the latest improvements I&#8217;d made to the code, and how it was going to improve the end-user&#8217;s experience despite being a mere refactor and a minor user interface tweak. I got bored after writing the first few paragraphs, and instead got distracted by the code, refactoring and tweaking it more than was necessary. A couple of hours in, I&#8217;d totally gold-plated the code in a way that I might have deemed unacceptable whilst on client time. This made me a little angry with&#8230;</p><p>The post <a href="http://pivotallabs.com/procrastination-considered-side-pet-project-soloing-versus-pairing/">Procrastination, considered.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://pivotallabs.com/find-test-pollution-rspec/">Last week</a> I blogged about a new project for aiding in the hunt for test pollution, <a href="https://github.com/camelpunch/scrubber">Scrubber</a>. This is a personal side project that I began recently. It&#8217;s in the very early stages, like many of my other pet projects. It&#8217;s something I&#8217;ve worked on entirely alone, though I&#8217;d also love to collaborate with others and/or pair on it.</p>
<p>I was going to blog this week about the latest improvements I&#8217;d made to the code, and how it was going to improve the end-user&#8217;s experience despite being a mere refactor and a minor user interface tweak. I got bored after writing the first few paragraphs, and instead got distracted by the code, refactoring and tweaking it more than was necessary. A couple of hours in, I&#8217;d totally <a href="http://en.wikipedia.org/wiki/Gold_plating_(software_engineering)">gold-plated</a> the code in a way that I might have deemed unacceptable whilst on client time. This made me a little angry with myself: why was I procrastinating from blogging, and was I a bad developer who&#8217;d lost the ability to work alone?</p>
<p>Something we&#8217;re encouraged to do at Pivotal Labs is reflect on our behavior. Thinking about my boredom and procrastination a little, I realized there was something more interesting going on. The process went a bit like this:</p>
<ol>
<li>Start blogging about the new features. Paste the visual output of the program into the blog post. Realize that the output didn&#8217;t meet the requirement of improving the user experience.</li>
<li>Start to implement the missing parts of the feature. Spend hours enjoying the freedom to refactor, delete and re-implement with no time limit, far more than when pairing on client time.</li>
</ol>
<p>When we pair, we have a safety net to catch us when we get distracted by neat language features or elegant implementation tricks. Our partner will often remind us that we&#8217;ve spent, say, two hours making no discernible feature changes and no improvement to maintainability of the code. When soloing, however, especially on pet projects, we are free to choose a goal for the activity. Sometimes we decide to perform <a href="http://en.wikipedia.org/wiki/Kata_(programming)">code katas</a>, but other times we don&#8217;t consciously choose a goal: the goal could become apparent during the activity itself. </p>
<p>So it seemed that I&#8217;d accidentally found validation in what I was doing, and a potentially more interesting blog post at the same time. I&#8217;d managed to get some programming exercise in instead of banging out a not-quite-earth-shattering new feature. Specifically, I:</p>
<ol>
<li>Thought like a user until it became obvious that changes were still needed. Switched to developer mode by accident.</li>
<li>Allowed myself to try out several approaches to the Presenter pattern, applying them to a trivial example that would not need a presenter in &#8216;real world&#8217; programming.</li>
<li>Used the <a href="http://sourcemaking.com/refactoring/introduce-null-object">Introduce Null Object</a> refactor in a situation that didn&#8217;t call for it. Yet, it felt good and might even prove useful for the project later.</li>
<li>Practiced several coding techniques that might become useful in the work environment.</li>
<li>Temporarily inverted my work-based insecurities about performance and timeliness, providing stress relief as an unexpected benefit of my brain switching itself off from the task at hand.</li>
</ol>
<p>Reflection is a useful technique for improving well-being. Your mileage may vary. If you&#8217;d have preferred to read about the changes made to Scrubber this week, you can read the <a href="https://github.com/camelpunch/scrubber/compare/3819f06...4261591">commit history</a>!</p>
<p>The post <a href="http://pivotallabs.com/procrastination-considered-side-pet-project-soloing-versus-pairing/">Procrastination, considered.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/procrastination-considered-side-pet-project-soloing-versus-pairing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fighting test pollution with an RSpec custom ordering strategy</title>
		<link>http://pivotallabs.com/find-test-pollution-rspec/</link>
		<comments>http://pivotallabs.com/find-test-pollution-rspec/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 06:02:49 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[bloggerdome]]></category>
		<category><![CDATA[ci]]></category>
		<category><![CDATA[minitest]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[test pollution]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=18500</guid>
		<description><![CDATA[<p>Test pollution manifests itself as seemingly false negatives or false positives in a test suite. It occurs when some shared state is unintentionally modified, or unintentionally read and used in a test. When test pollution builds up, it can mean that a project&#8217;s build fails unpredictably, which can stop a whole team from shipping code regularly. This is an expensive way to not build software. Here&#8217;s an example of test pollution. You can save and run it with Ruby if you like. You shouldn&#8217;t need anything but a recent version of Ruby. If you run it several times, it will sometimes fail and sometimes pass: Why is it so unreliable? MiniTest orders tests randomly by default. When the first test runs before the second test, the test case fails, because the first test has the effect of setting the @logged_in instance variable to true, and the second test is effectively&#8230;</p><p>The post <a href="http://pivotallabs.com/find-test-pollution-rspec/">Fighting test pollution with an RSpec custom ordering strategy</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Test pollution manifests itself as seemingly false negatives or false positives in a test suite. It occurs when some shared state is unintentionally modified, or unintentionally read and used in a test.</p>
<p>When test pollution builds up, it can mean that a project&#8217;s build fails unpredictably, which can stop a whole team from shipping code regularly. This is an expensive way to not build software.<br />
<span id="more-18500"></span><br />
Here&#8217;s an example of test pollution. You can save and run it with Ruby if you like. You shouldn&#8217;t need anything but a recent version of Ruby. If you run it several times, it will sometimes fail and sometimes pass:</p>
<script src="https://gist.github.com/5449597.js?file=test_pollution.rb"></script><noscript><pre><code class="language-ruby ruby">require 'minitest/autorun'

class User
  def self.login(username, password)
    if username == 'fred' &amp;&amp; password == '123'
      @logged_in = true
    end
  end

  def self.logged_in?
    @logged_in == true
  end
end

class UserTest &lt; MiniTest::Unit::TestCase
  def test_logs_in_if_correct_credentials_used
    User.login('fred', '123')
    assert User.logged_in?
  end

  def test_doesnt_log_in_if_incorrect_credentials_used
    User.login('bill', '321')
    refute User.logged_in?, &quot;User was logged in, but expected not to be&quot;
  end
end
</code></pre></noscript>
<p>Why is it so unreliable? MiniTest orders tests randomly by default. When the first test runs before the second test, the test case fails, because the first test has the effect of setting the @logged_in instance variable to true, and the second test is effectively expecting the value of @logged_in to be false. The code under test has <em>global state</em>: the class instance variable, @logged_in.</p>
<p>The problem with the first test is that it&#8217;s a bad citizen: it sets global state and doesn&#8217;t clean itself up. The problem with the second test is that it&#8217;s presumptuous: it relies on global state being something in particular. As an aside: the code is terrible, and the flakiness of these tests should prompt you to change it, but I used a contrived example for the purpose of demonstration.</p>
<h2>Fighting pollution with existing tools</h2>
<p>I mentioned that MiniTest orders tests randomly by default. This is a Good Thing: it&#8217;s a deliberate ploy to flush out test pollution. If you ran the above code and it failed, it would give you a &#8216;seed&#8217; number to pass in to the test, so that you could consistently run the test in the failing order. From there, you could hopefully work out why the particular order of tests failed. Both RSpec and MiniTest allow you to run tests in a random order, and both allow you to re-use the order from a previous failed run.</p>
<p>These aspects of MiniTest and RSpec are useful. They allow you to fix the order, so that you can find the dirty polluters of your test suite. This is often a quest to find two items: a polluter and a polluted test. Often you&#8217;ll find more than two, or a strange combination of tests that, when run in a particular order, cause a failed build.</p>
<p>On larger projects, these tools aren&#8217;t enough. Large codebases tend to have correspondingly large, slow test suites. Finding a source of test pollution in such beasts can involve looking at a lot of code, and can take a very long time.</p>
<h2>Why can&#8217;t we automate this?</h2>
<p>We&#8217;ve seen above that tests are reorderable chunks of code. So, you&#8217;d think that digging through reams of code just to reduce a pass/fail situation down to two examples would be an automatable process. You&#8217;d be right, but it&#8217;s not as straightforward as it ought to be.</p>
<p>When <a href="http://pivotallabs.com/team/?as=colin+o&#038;submit=%3F">my pair</a> and I first set out to write a tool to reduce tests down to their polluting / polluted components we thought we could get RSpec to output a list of files. We could then just feed the list of files back into RSpec in the order in which they failed, and use a <a href="http://en.wikipedia.org/wiki/Binary_search">binary search</a> to find the offending files.</p>
<p>Unfortunately, it&#8217;s not that easy. RSpec isn&#8217;t file-centric, but groups-and-examples-centric. For the uninitiated, an RSpec test is composed of groups and examples:</p>
<script src="https://gist.github.com/5449597.js?file=rspec.rb"></script><noscript><pre><code class="language-ruby ruby">describe &quot;some group&quot; do
  example &quot;example 1&quot; do
    expect(@triangle).to have(2).sides
  end
  
  describe &quot;some sub group&quot; do
    it &quot;has another example, using the 'it' alias&quot; do
      expect(@circle).to be_square
    end
  end
  
  example &quot;example 2&quot; do
    expect(@square).to have(3).sides
  end
end</code></pre></noscript>
<p>Once test files are processed, they&#8217;re loaded into memory and randomized regardless of file (but keeping group hierarchy intact). <a href="https://github.com/rspec/rspec-core/blob/ec10d7889192150ed40a04647cbfe70cfd2be5f0/lib/rspec/core/configuration.rb#L937-942">RSpec&#8217;s randomization algorithm</a> is pretty simplistic:</p>
<ol>
<li>Programmer: Hey RSpec, run the suite with this seed: 123</li>
<li>RSpec: I found a set of sibling groups. What should I do?</li>
<li>Randomizer: &#8216;Randomize&#8217; them according to the number of items in the set, with this seed: 123</li>
<li>RSpec: OK, I&#8217;ve got a set of sibling examples inside one of the groups. What should I do?</li>
<li>Randomizer: &#8216;Randomize&#8217; them according to the number of items in the set, with this seed: 123</li>
</ol>
<p>And so on. This approach is great so long as you don&#8217;t want to reduce the problem set. If you do reduce the set of examples that RSpec is running, the order is lost, because the number of items in the list changes.</p>
<h2>Enter The Scrubber</h2>
<p>I&#8217;d ideally like to tell a computer to go and find my test pollution. I&#8217;m some of the way there. So far, I&#8217;ve managed to create a semi-automatic solution: get RSpec to output the order of a test run to a human-readable file, so that it can be edited and fed back into RSpec to order the next run.</p>
<p><a href="https://github.com/camelpunch/scrubber">Scrubber</a> is a project I started last week that allows you to persist RSpec run orders, edit them, and replay them. It relies on a <a href="http://blog.davidchelimsky.net/2012/11/12/rspec-212-is-released/">relatively new feature of RSpec</a> that allows you to define custom ordering strategies. These strategies are just blocks of code that take as an input the list of groups or examples in a particular section of your suite, and return the groups or examples you want, in the order you want them.</p>
<p>The main stumbling block when writing the utility has been deriving a unique ID from each example or example group. The ID needs to be human readable and also reproducible across runs. So far I have a simplistic solution that just dumps the group or example description, and file location. This isn&#8217;t very unique, especially considering that RSpec has no restriction on having groups or examples with duplicate descriptions.</p>
<p>In future, I hope to use a more robust ID, perhaps a checksum of the example/group&#8217;s metadata. Again, this isn&#8217;t straightforward as some of the metadata are Proc objects. Perhaps the RSpec team would be interested in persistable suite runs as a core feature?</p>
<p>Anyway, <a href="https://github.com/camelpunch/scrubber/blob/master/examples/example.rb">here&#8217;s an example of Scrubber in use</a>. If you&#8217;re interested, I suggest you <a href="https://github.com/camelpunch/scrubber">clone the repo</a> and have a play with the example to see how editing a file might work. It&#8217;s very rough around the edges right now, but serves as a proof of concept. Hopefully I&#8217;ll get enough time, or contributors, to make this into something more automated and user-friendly.</p>
<p>The post <a href="http://pivotallabs.com/find-test-pollution-rspec/">Fighting test pollution with an RSpec custom ordering strategy</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/find-test-pollution-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rager Party (Standup 7/31/12)</title>
		<link>http://pivotallabs.com/rager-party-standup-7-31-12/</link>
		<comments>http://pivotallabs.com/rager-party-standup-7-31-12/#comments</comments>
		<pubDate>Tue, 31 Jul 2012 17:09:00 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Standup]]></category>
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/rager-party-standup-7-31-12/</guid>
		<description><![CDATA[<p><h2>Helps</h2>

<ul>
<li>New Mail Rack</li>
</ul>

<p>There's a new mail rack near the lockers.</p>

<ul>
<li>Capybara inconsistent about what page it's on</li>
</ul>

<p>We have a spec that does something along the lines of</p>

<pre><code>visit '/#foo'
visit '/#bar'
save_and_open_page
page.should have_content&#40;&#38;quot;bar&#38;quot;&#41;
</code></pre>

<p>The <code>save_and_open_page</code> gives the bar page, but the assertion fails because it looks for &#34;bar&#34; in the contents of the foo page rather than the bar page.</p>

<p>One suggestion was to tell capybara to resync.</p>

<ul>
<li>Webviews for iOS app - slow?</li>
</ul>

<p>One team was worried about the speed of Webviews versus the speed of e.g. mobile Safari. It was suggested to try it and see, benchmark even.</p>

<h2>Interestings</h2>

<ul>
<li>Mad at your Rails logs? Try Lograge</li>
</ul>

<p><a href="Lograge">https://github.com/roidrage/lograge</a> uses the amazing notification system in Rails 3 - which itself is worth a read - to make more useful logs for staging &#38; production environments. Looks like it came out of the TravisCI project. And if you're logging to Splunk, this is more like what you want.</p>

<ul>
<li>Jasmine busted after Firefox upgrade?</li>
</ul>

<p>Upgrade the selenium-webdriver gem to 2.25.0 and happiness will prevail.</p> <a href="http://pivotallabs.com/rager-party-standup-7-31-12/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/rager-party-standup-7-31-12/">Rager Party (Standup 7/31/12)</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>Helps</h2>
<ul>
<li>New Mail Rack</li>
</ul>
<p>There&#8217;s a new mail rack near the lockers.</p>
<ul>
<li>Capybara inconsistent about what page it&#8217;s on</li>
</ul>
<p>We have a spec that does something along the lines of</p>
<pre><code>visit '/#foo'
visit '/#bar'
save_and_open_page
page.should have_content&#40;&amp;quot;bar&amp;quot;&#41;
</code></pre>
<p>The <code>save_and_open_page</code> gives the bar page, but the assertion fails because it looks for &quot;bar&quot; in the contents of the foo page rather than the bar page.</p>
<p>One suggestion was to tell capybara to resync.</p>
<ul>
<li>Webviews for iOS app &#8211; slow?</li>
</ul>
<p>One team was worried about the speed of Webviews versus the speed of e.g. mobile Safari. It was suggested to try it and see, benchmark even.</p>
<h2>Interestings</h2>
<ul>
<li>Mad at your Rails logs? Try Lograge</li>
</ul>
<p><a href="Lograge">https://github.com/roidrage/lograge</a> uses the amazing notification system in Rails 3 &#8211; which itself is worth a read &#8211; to make more useful logs for staging &amp; production environments. Looks like it came out of the TravisCI project. And if you&#8217;re logging to Splunk, this is more like what you want.</p>
<ul>
<li>Jasmine busted after Firefox upgrade?</li>
</ul>
<p>Upgrade the selenium-webdriver gem to 2.25.0 and happiness will prevail.</p>
<p>The post <a href="http://pivotallabs.com/rager-party-standup-7-31-12/">Rager Party (Standup 7/31/12)</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/rager-party-standup-7-31-12/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SF Standup &#8211; March 1st, 2012: so who&#8217;s deployed Carrierwave?</title>
		<link>http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/</link>
		<comments>http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 20:50:00 +0000</pubDate>
		<dc:creator>Andrew Bruce</dc:creator>
				<category><![CDATA[Standup]]></category>
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/</guid>
		<description><![CDATA[<p><h1>Requests for help</h1>

<blockquote>
    <p><em>"How do I avoid compiling gems on production servers?"</em></p>
</blockquote>

<p>Apparently there's a project that Chef uses that packages dependencies into an installer.</p>

<p>Also, <a href="https://github.com/jordansissel/fpm/wiki">FPM</a> is potentially a good solution.</p>

<h1>Interesting</h1>

<p>Survey: who's actually deployed Carrierwave?</p>

<p>2 people said they had.</p> <a href="http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/">SF Standup &#8211; March 1st, 2012: so who&#8217;s deployed Carrierwave?</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<h1>Requests for help</h1>
<blockquote>
<p><em>&#8220;How do I avoid compiling gems on production servers?&#8221;</em></p>
</blockquote>
<p>Apparently there&#8217;s a project that Chef uses that packages dependencies into an installer.</p>
<p>Also, <a href="https://github.com/jordansissel/fpm/wiki">FPM</a> is potentially a good solution.</p>
<h1>Interesting</h1>
<p>Survey: who&#8217;s actually deployed Carrierwave?</p>
<p>2 people said they had.</p>
<p>The post <a href="http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/">SF Standup &#8211; March 1st, 2012: so who&#8217;s deployed Carrierwave?</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/sf-standup-march-1st-2012-so-who-s-deployed-carrierwave/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using apc
Database Caching using apc
Object Caching 1220/1321 objects using apc

 Served from: pivotallabs.com @ 2013-06-19 22:06:18 by W3 Total Cache -->