Do not write any code unless you know why the user cares.
We have two ways of knowing whether a user cares: the design, and the acceptance specification.
When starting a feature, we start with a design. What we mean by this can be vaguely high level, or it can be exact. Here are two example stories:
We “design” both of these first. The first one gets a visual: either a drawing on a piece of paper, or a HTML wireframe, or a full template using high_voltage, or something else.
The second example is harder to represent visually, so it gets a more detailed user experience discussion, coupled with diagrams: which news articles, how do they get these articles, how do they know it’s 15 minutes faster—and all of that leads into a visual to work off, too.
Much has been written about acceptance specs through the ages, but a topic that continues to arise is that of varying level of detail. Here are two examples:
Scenario: Moderator marks messages as spam
Given a user exists with a username of "joey user"
And the following message exists:
| user:username | subject |
| joey user | Subjects are lame |
And I am signed in as a moderator
When I go to the spams page
And I follow "Subjects are lame"
And I press "Spam"
Then I should see "the message has been marked as spam"
Given I am signed in as "joey user"
When I go to the messages page
Then I should not see "Subjects are lame"
Scenario: Moderator marks messages as spam
Given a user has a message
And I am signed in as a moderator
When I mark that message as spam
Then the user should not see the message
<p>The first scenario spells out exactly what to do, step-by-step. It is
written as if I were using a super lame programming language that didn’t have abstractions. The second scenario describes the user’s experience; it describes the reason to care about the whole concept.
The second scenario is very closely related to the design discussion: all the key points of the discussion are there, with none of the boring details (like the fact that messages can have subjects). Moreover, it’s readable.
“OK, great,” you say. “Woo hoo, cucumber. So what?”
Cut the sass; you can do this in Rspec too:
describe 'moderation (like smoking cigars)' do
it 'works as expected when the moderator marks a message as spam' do
harness.make_user_with_message
harness.sign_in_as_moderator
harness.mark_the_message_as_spam
harness.user_should_not see_the_message
end
let(:harness) { ModerationTestHarness.new }
end
There are at least four reasons why you absolutely need to start doing both of these things right now:
End-to-end testing with RSpec integration tests and Capybara
Describe the User’s Perspective: DDD, acceptance testing, and you