Coulda - Simplifying BDD
Coulda is YAFTL*. It's a little guy that stands on the shoulders of giants.
Seriously speaking, Coulda is an internal DSL that is similar to RSpec StoryRunner, the predecessor of Cucumber's Gherkin external DSL.
When used, it can look like this:
Feature "Define a feature" do in_order_to "write acceptance tests with less code" as_a "developer" i_want_to "use a simple internal DSL" Scenario "Demonstrate how coulda works" do Given "a pending prereq" do # Precondition code could go here end When "something happens" do # Behavior to test invoked here end Then "expect something else" do # Assertions on result of behavior go here end end end
But it can also be easily rendered as plain text (via a rake task) to look like this:
Feature: Define a feature In order to write acceptance tests with less code As a developer I want to use a simple internal DSL Scenario: Demonstrate how coulda works Given a pending prereq When something happens Then expect something else
Getting Started
Install the gem:
sudo gem install coulda
(unless you're using RVM -- which you probably should be in which case it's "gem install coulda")
Then write some user stories/features/specs/tests/acceptance tests/your-name-du-jour-for-a-descriptive-testing-artifact
Rendering stories as text
It's this easy:
RAILS_ENV=test rake coulda:print_features
And then you get this:
Feature: Define a feature In order to write acceptance tests with less code As a developer I want to use a simple internal DSL Scenario: Demonstrate how coulda works Given a pending prereq When something happens Then expect something else