Coulda: A Cucumber-like DSL for BDD

cucumberEvan Light has recently pushed his Coulda project to Github - it's a test framework based on Test::Unit, inspired by Cucumber, Shoulda and Thor.

Coulda works like Cucumber in that it's a Domain Specific Language for capturing the behaviour expected by your code, as part of the Behavior Driven Develoment approach (BDD). Others have noted it's a little like the RSpec story runner.

Where Coulda differs is that instead of using Gherkin to convert your statements about the behavior to code using regular expressions, it uses standard method calls. This is less of a cognitive leap for the developer... with Coulda, you can test like you code.

require 'rubygems'
require 'coulda'
include Coulda

Feature "feature name" do
  in_order_to "foo"
  as_a "bar"
  i_want_to "blech"

  def something
  end

  def expectation
  end

  Scenario "pending scenario"

  Scenario "another scenario" do
    Given "a pending prereq"
    When "something happens" do
      something
    end
    Then "expect something else" do
      expectation
    end
  end

  Scenario "that is live" do
    Given "foo" do; end
    When "bar" do; end
    Then "blech" do; end
  end
end

To be honest, I'm not a big user of Cucumber, so I'm not able to give much of an intelligent commentary here - I suggest you read more about Coulda on Evan's blog. You can get the code on Github.

devver-icon.gifAlso.. Got a slow Test::Unit or RSpec suite? Run them up to three times faster on Devver's cloud! Setup is simple and requires no code changes. Sign up now!

Images: