Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b53ccffa14
Fetching contributors…

Cannot retrieve contributors at this time

127 lines (96 sloc) 3.287 kb
---
title: home
order: 1
filter:
- erb
- textile
---
h2. Overview
RSpec is a testing tool for the Ruby programming language. Born under the banner of Behaviour-Driven Development, it is designed to make Test-Driven Development a productive and enjoyable experience with features like:
* a rich command line program (the rspec command)
* textual descriptions of examples and groups ("rspec-core":http://rubydoc.info/gems/rspec-core/frames)
* flexible and customizable reporting
* extensible expectation language ("rspec-expectations":http://rubydoc.info/gems/rspec-expectations/frames)
* built-in mocking/stubbing framework ("rspec-mocks":http://rubydoc.info/gems/rspec-mocks/frames)
h2. Documentation
RDoc
* "http://rubydoc.info/gems/rspec-core":http://rubydoc.info/gems/rspec-core/frames
* "http://rubydoc.info/gems/rspec-expectations":http://rubydoc.info/gems/rspec-expectations/frames
* "http://rubydoc.info/gems/rspec-mocks":http://rubydoc.info/gems/rspec-mocks/frames
* "http://rubydoc.info/gems/rspec-rails":http://rubydoc.info/gems/rspec-rails/frames
Cucumber Features
* "http://relishapp.com/rspec":http://relishapp.com/rspec
RSpec-1.x
* "http://old.rspec.info":http://old.rspec.info
h2. The RSpec Book
<div style="float:right">
<a target="_blank" href="http://www.pragprog.com/titles/achbd/the-rspec-book">
<img width="190" height="228" border="0" title="The RSpec Book" alt="The RSpec Book" src="http://imagery.pragprog.com/products/140/achbd_xlargecover.jpg"/>
</a>
</div>
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.
h2. Get Started Now
<pre>
$ gem install rspec
</pre>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<p>
Start with a very simple example that expresses
some basic desired behaviour.
</p>
<% coderay(:language => 'ruby') do -%>
# 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 eq(0)
end
end
<% end -%>
<p>
Run the example and watch it fail.
</p>
<pre style="color:red;">
$ rspec bowling_spec.rb
./bowling_spec.rb:4:
uninitialized constant Bowling
</pre>
</td>
<td width="50%">
<p>
Now write
just enough code to make it pass.
</p>
<% coderay do -%>
# bowling.rb
class Bowling
def hit(pins)
end
def score
0
end
end
<% end -%>
<p>
Run the example and bask in the joy that is green.
</p>
<pre style="color:green;">
$ rspec bowling_spec.rb --format nested
Bowling#score
returns 0 for all gutter game
Finished in 0.007534 seconds
1 example, 0 failures
</pre>
</td>
</tr>
</table>
h2. 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.
h2. Take the first step now!
<pre>
gem install rspec
</pre>
Jump to Line
Something went wrong with that request. Please try again.