Dan mentions that he is discussing integrating his work into RSpec at some point in the future, but in the meantime Dan's rBehave framework is currently at version 0.3.0 and is available for install as a Ruby Gem as usual:
sudo gem install rbehaveDan gives an example of rBehave using a bank transfer story on his blog. Below I give another example of authenticating a user:
require ‘rubygems’
require ‘rbehave’
require ’spec’ # for "should" method
require ‘user’ # the actual application code
Story "authenticate user",
%(As a user of the system I wish to authenticate and access my account information.) do
Scenario "correct password is supplied but user has been suspended" do
Given "my user account is created", User.new do |user|
@user = User.new
end
Given "my username is", "myusername" do |username|
@user.username = username
end
Given "my password is", "mypassword" do |password|
@user.password = password
end
Given "my user account has been suspended", true do |suspended|
@user.suspended = suspended
end
When "I attempt to authenticate with", "mypassword" do |password|
@authenticated = @user.authentiate?(password)
end
Then "my user account should respond with authentication status of", false do |status|
@authenticated.should be(status)
end
end
Scenario "correct password is supplied and user is active and verified" do
Given "my user account is created", User.new
Given "my username is", "myusername"
Given "my password is", "mypassword"
Given "my user account has been suspended", false
Given "my user account has been activated", true do |activated|
@user.activated = activated
end
When "I attempt to authenticate with", "mypassword"
Then "my user account should respond with authentication status of", true
end
# A few other scenarios go here, like non-activated user (but not suspended), etc.
# Left as exercise to the reader.
end
Please note, i do not need to restate the Given, When or Then blocks passed in after they are defined once!