The RSpec Book: Behaviour Driven Development with RSpec, Cucumber, and Friends

You’ll get started right away with RSpec 2 and Cucumber by developing a simple game, using Cucumber to express high-level requirements in language your customer understands, and RSpec to express more granular requirements that focus on the behavior of individual objects in the system. You’ll learn how to use test doubles (mocks and stubs) to control the environment and focus the RSpec examples on one object at a time, and how to customize RSpec to „speak“ in the language of your domain.

You’ll develop Rails 3 applications and use companion tools such as Webrat and Selenium to express requirements for web applications both in memory and in the browser. And you’ll learn to specify Rails views, controllers, and models, each in complete isolation from the other.

Whether you’re developing applications, frameworks, or the libraries that power them, The RSpec Book will help you write better code, better tests, and deliver better software to happier users.

Screencast: Pickle mit Cucumber

Neue Woche, neuer Screencast. In dieser Woche behandelt Ryan Pickle, eine Erweiterungs-Gem für Cucumber. Nebenbei gibt es ein bisschen Knowhow zu diffs.

Download(32.5 MB, 16:43)
alternativer download für iPod & Apple TV (21.7 MB, 16:43)



rails store
sudo rake gems:install RAILS_ENV=test
script/generate cucumber
script/generate pickle
script/generate rspec_model product name:string price:decimal
rake db:migrate
rake db:test:clone
script/generate rspec_controller products show
cucumber features -q

# config/environments/test.rb
config.gem "rspec", :lib => false, :version => ">=1.2.9"
config.gem "rspec-rails", :lib => false, :version => ">=1.2.9"
config.gem "webrat", :lib => false, :version => ">=0.5.3"
config.gem "cucumber", :lib => false, :version => ">=0.4.3"
config.gem "pickle", :lib => false, :version => ">=0.1.21"

# product_steps.rb
Then(/^I should see products table$/) do |expected_table|
html_table = table_at("#products").to_a! { |r|! { |c| c.gsub(/<.+?>/, “) } }

# display_products.feature
Feature: Display Products
In order to purchase the right product
As a customer
I want to browse products and see detailed information

Scenario: Show product
Given a product exists with name: "Milk", price: "2.99"
When I go to the show page for that product
Then I should see "Milk" within "h1"
And I should see "$2.99"

Scenario: List products
Given the following products exist
| name | price |
| Milk | 2.99 |
| Puzzle | 8.99 |
When I go to path "/products"
Then I should see products table
| Milk | $2.99 |
| Puzzle | $8.99 |
Then show me the page