Sha256: c1e70895398335a46372f098839d5af84e692b2f052d1818f26c897d99c9c81b

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

---
title: RSpec on Rails
inMenu: true
---
h2. RSpec on Rails

RSpec's rspec_generator Rubygem brings RSpec to Rails.

h3. Features

* Integrated fixture loading
* Uses many of the controller-test integration features
* Special generators for models and controllers that generate specs instead of tests.

h3. Installation

RSpec support for rails lives in a separate gem. Install that gem:

<pre>
gem install rspec_generator
</pre>

Once the gem is installed, you must configure you Rails app. Stand in the root of your Rails app and run:

<pre>
ruby script/generate rspec
</pre>

Now, you can generate models and controllers in a similar fashion to Rails' builtin generators. Example:

<pre>
ruby script/generate rspec_model person
</pre>

or

<pre>
ruby script/generate rspec_controller person
</pre>

For more information on each generator, just run them without any arguments.

h3. Running specs

All specs can be run with

<pre>
rake spec
</pre>

Model specs can be run with

<pre>
rake spec:models
</pre>

Controller specs can be run with

<pre>
rake spec:controllers
</pre>

To see all the RSpec related tasks, run

<pre>
rake --tasks spec
</pre>

h3. Naming conventions

When you use Rails without RSpec (with Test::Unit), tests for models end up in tests/unit and tests for controllers
end up in tests/functional.

In order to make things more consistent, RSpec chooses a slightly different naming convention for direcotries and
Rake tasks. So you will find model specs under specs/models, and controller specs under specs/controllers. The
Rake tasks are named accordingly.

h3. Examples

RSpec on Rails adds several methods to your specs with a look and feel similar to Test::Unit. Example:

Model:
<ruby file="../vendor/rspec_on_rails/spec/models/person_spec.rb"/>

Controller:
<ruby file="../vendor/rspec_on_rails/spec/controllers/person_controller_spec.rb"/>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-0.5.10 doc/src/tools/rails.page
rspec-0.5.7 doc/src/tools/rails.page
rspec-0.5.8 doc/src/tools/rails.page
rspec-0.5.9 doc/src/tools/rails.page