Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
features
lib
spec
templates
.gitignore
Gemfile
README.markdown
Rakefile
VERSION
example_app_template.rb
rspec-rails.gemspec
specs.watchr

README.markdown

RSpec-2 for Rails-3

Backwards compatibility

None. This is a rewrite of the rspec-rails extension designed to work with rails-3.x and rspec-2.x. It will not work with older versions of either rspec or rails.

Current state

Currently in alpha - some things work, some not so much - see Known Issues, below

Install:

gem install rspec-rails --pre

This installs the following gems:

  • rspec
  • rspec-core
  • rspec-expectations
  • rspec-mocks
  • rspec-rails

Configure:

Add this line to the Gemfile:

gem "rspec-rails", ">= 2.0.0.beta.8"

This will expose generators, including rspec:install. Now you can run:

script/rails g rspec:install

This adds the spec directory and some skeleton files, including the "rake spec" task.

Note that things are in flux, so some generators generate code that doesn't work all that well yet.

What works (and what doesn't)

Currently supported:

  • each example runs in its own transaction
    • configurable in Rspec.configure
      • see generated spec/spec_helper.rb
  • model specs in spec/models
  • controller specs in spec/controllers
    • no view isolation yet
  • view specs in spec/views
  • mailer specs in spec/mailers
  • observer specs in spec/models
  • request specs in spec/requests
    • these wrap rails integration tests
  • rails assertions
  • assertion-wrapping matchers
    • redirect_to
    • render_template
      • template must exist (unlike rspec-rails-1.x)
  • webrat matchers
  • generators
    • run "script/rails g" to see the list of available generators

Known issues

  • no helper specs
  • no routing specs
  • only works with ActiveRecord

Controller Specs

Controller specs live in spec/controllers, and mix in ActionController::TestCase::Behavior. See the documentation for ActionController::TestCase to see what facilities are available from Rails.

You can use RSpec expectations/matchers or Test::Unit assertions.

In addition to what Rails offers, controller specs provide all of rspec-core's matchers and the rspec-rails' specific matchers as well.

Matchers

render_template

Delegates to Rails' assert_template:

response.should render_template("new")

redirect_to

Delegates to assert_redirect

response.should redirect_to(widgets_path)
Something went wrong with that request. Please try again.