Ben Biddington

Whatever it is, it's not about "coding"

Posts Tagged ‘bdd

RSpec — common base specs

leave a comment »

Sometimes I am fond of creating inheritance chains for tests, which is easy in Java or C# say, but not quite as obvious in rspec.

Define and register a base class

It just needs to inherit from Spec::Example::ExampleGroup so it’s runnable.

require 'spec/example/example_group'
class UnitTest < Spec::Example::ExampleGroup
   def you_can_call_this

Spec::Example::ExampleGroupFactory.register(:unit_test, UnitTest)

Set the type when describing

describe 'By supplying the :type', :type => :unit_test do
    it 'this example group inherits from whatever class you supply as :type' do
        self.protected_methods.should include('you_can_call_this')

You now have common base class to your specifications.

Written by benbiddington

6 November, 2010 at 13:37

Posted in development

Tagged with , ,

Outside-in development taken too far

with 2 comments

You may feel someone is taking things too far when you receive a set of scenarios like this:

Scenario 1: Warm Teapot

Given a Kettle of Boiling Water
When Boiling Water is poured in to the Teapot
Then it should* warm the Teapot

Scenario 2: Brewing the tea

Given a Kettle of Boiling Water
And 5 Teabags
When 5 Teabags are placed in the Teapot
And Boiling Water is poured in to the Teapot
And the Teapot is left with the above ingredients in it for 5 minutes
Then you should have Brewed Tea

Scenario 3: Pouring the tea

Given a Teapot of Brewed Tea
And a Mug with some Milk in it**
When the Brewed Tea is poured in to the Mug
Then you should have a Perfect Cup of Tea

* “Do or do not. There is no should”
** Debatable. I think we need to triangulate this, or consult the client.

Written by benbiddington

3 August, 2010 at 13:37

Posted in development

Tagged with , , ,