This is documentation for RSpec-1.
For RSpec-2, please see http://rspec.info
We will eventually point http://rspec.info directly to the rspec 2, but we want to support old links from books and blogs. If you’re interested in volunteering to write an app to manage redirects, please contact rspec-users@rubyforge.org.
Overview
RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.
The RSpec Book
The RSpec Book will introduce you to RSpec, Cucumber, and a number of other tools that make up the Ruby BDD family. Replete with tutorials and practical examples, the RSpec Book will help you get your BDD on, taking you from executable requirements to working software that is clean, well tested, well documented, flexible and highly maintainable.
More information
http://blog.davidchelimsky.net
RSpec-2
Cucumber features
http://wiki.github.com/rspec/rspec
http://github.com/rspec
http://github.com/rspec/rspec-core
http://github.com/rspec/rspec-expectations
http://github.com/rspec/rspec-mocks
http://github.com/rspec/rspec-rails
RSpec-1
http://wiki.github.com/dchelimsky/rspec
http://rspec.lighthouseapp.com
Get Started Now
$ gem install rspec
|
Start with a very simple example that expresses some basic desired behaviour. # bowling_spec.rb require 'bowling' describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } bowling.score.should == 0 end end Run the example and watch it fail. # rspec-2 $ rspec bowling_spec.rb # rspec-1 $ spec bowling_spec.rb ./bowling_spec.rb:4: uninitialized constant Bowling |
Now write just enough code to make it pass. # bowling.rb class Bowling def hit(pins) end def score 0 end end
Run the example and bask in the joy that is green. # rspec-2 $ rspec bowling_spec.rb --format nested # rspec-1 $ spec bowling_spec.rb --format nested Bowling#score returns 0 for all gutter game Finished in 0.007534 seconds 1 example, 0 failures |
Take very small steps
Don’t rush ahead with more code. Instead, add another example and let it guide you to what you have to do next. And don’t forget to take time to refactor your code before it gets messy. You should keep your code clean at every step of the way.
