Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rspec-2 runner and formatters

Fetching latest commit…

Cannot retrieve the latest commit at this time

RSpec Core

RSpec Core provides the structure for writing executable examples of how your code should behave.

build status


The Cucumber features are the most comprehensive and up-to-date docs for end-users.

The RDoc provides additional information for contributors and/or extenders.

All of the documentation is open source and a work in progress. If you find it lacking or confusing, you can help improve it by submitting requests and patches to the rspec-core issue tracker.


gem install rspec      # for rspec-core, rspec-expectations, rspec-mocks
gem install rspec-core # for rspec-core only

Upgrading from rspec-1.x

See features/

This will install the rspec, rspec-core, rspec-expectations and rspec-mocks gems.

Get Started

Start with a simple example of behavior you expect from your system. Do this before you write any implementation code:

# in spec/calculator_spec.rb
describe Calculator, "add" do
  it "returns the sum of its arguments" do, 2).should eq(3)

Run this with the rspec command, and watch it fail:

$ rspec spec/calculator_spec.rb
./spec/calculator_spec.rb:1: uninitialized constant Calculator

Implement the simplest solution:

# in lib/calculator.rb
class Calculator
  def add(a,b)
    a + b

Be sure to require the implementation file in the spec:

# in spec/calculator_spec.rb
# - RSpec adds ./lib to the $LOAD_PATH, so you can
#   just require "calculator" directly
require "calculator"

Now run the spec again, and watch it pass:

$ rspec spec/calculator_spec.rb

Finished in 0.000315 seconds
1 example, 0 failures

Use the documentation formatter to see the resulting spec:

$ rspec spec/calculator_spec.rb --format doc
Calculator add
  returns the sum of its arguments

Finished in 0.000379 seconds
1 example, 0 failures

Known issues


Learn more

While not comprehensive yet, you can learn quite a lot from the Cucumber features in the features directory. If there is a feature that is not documented there, or you find them insufficient to understand how to use a feature, please submit issues to



Troubleshooting the environment

unterminated string meets end of file (SyntaxError)

If you want to run tests without using rake, you have to know that running:

rspec .

You will see syntax error, because rspec try to execute some files in lib folder.
When you want to run tests you have to run:

rspec spec/.

Rspec will execute just the files in spec folder. Using rake you haven't this problem.

different problem?

If you run into a problem not documented here, please check the rspec-dev issues tracker to see if someone else has already reported it. If not, please add one.

solution to a problem not documented here?

If you solve a problem that is not documented here, please share the love by submitting a patch to this README.

Also see

Something went wrong with that request. Please try again.