Monday, April 6, 2009

Wiki Specifcations

‹prev | My Chain | next›

Realizing that I had overlooked recipe summary and instructions, I get started on them tonight. The feature scenario:
    Scenario: Viewing summary and recipe instructions

Given a recipe for Curried Shrimp
When I view the recipe
Then I should a nice summary of the dish
And I should see detailed, easy-to-read instructions
The inside view specs are straight-forward:
  it "should display the recipe's summary" do
self.stub!(:wiki).and_return("wiki #{@summary}")

response.should have_selector("#eee-summary",
:content => "wiki #{@summary}")

it "should display the recipe's instructions" do
self.stub!(:wiki).and_return("wiki #{@instructions}")

response.should have_selector("#eee-instructions",
:content => "wiki #{@instructions}")
The not-so-trivial part of working inside the guts of the application is that wiki helper method. In addition to textilizing text, it performs various domain-specific clean-up such as converting 250F to 250° F, replacing recipe URIs with linked titles and replacing our kids names with nicknames.

Happily, I spent quite a bit of time getting helpers into controller specs. Even better, that work makes direct helper specifications trivial:
require File.expand_path(File.dirname(__FILE__) + '/spec_helper' )

describe "wiki" do
it "should return simple text as unaltered text" do
wiki("bob").should == "bob"
it "should convert textile to HTML"
it "should wikify temperatures"
it "should wikify kids names"
it "should wikify recipe URIs"
A trivial implementation of the wiki makes this spec pass:
    def wiki(text)

Next up: making those other 4 examples pass.

No comments:

Post a Comment