--- 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:
gem install rspec_generator
Once the gem is installed, you must configure you Rails app. Stand in the root of your Rails app and run:
ruby script/generate rspec
Now, you can generate models and controllers in a similar fashion to Rails' builtin generators. Example:
ruby script/generate rspec_model person
or
ruby script/generate rspec_controller person
For more information on each generator, just run them without any arguments. h3. Running specs All specs can be run with
rake spec
Model specs can be run with
rake spec:models
Controller specs can be run with
rake spec:controllers
To see all the RSpec related tasks, run
rake --tasks spec
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: Controller: