Agile Web Development

Build it. Launch it. Love it.

RSpec on Rails

Mashes Rails’ Test::Unit::TestCase fixture loading with RSpec.

It allows you to use rspec (http://rspec.rubyforge.org) with rails.

  • load fixtures like normal rails testing
  • use many of the controller-test integration features

Installation:

The plugin automatically creates a RAILS_ROOT/spec directory. It then copies over a default spec_helper.rb and creates unit, functional and fixtures sub-directories

Usage:

a spec might look like

require File.dirname(FILE) + ’/../spec_helper’

  context "the Person model" do
    fixtures :people

    setup do
      # fixtures are setup before this
      puts "setup" # stuff
    end

    specify "should find an existing person" do
      person = Person.find(1)

      person.should.not.be nil
      person.should.equal people(:billy)
      person.name.should.equal 'billy'
    end

    teardown do
      puts "teardown" # stuff
      # fixtures are torn down after this
    end
  end

You run the spec like

$ spec -v person_spec.rb

Controller spec Usage:

  context "The Families controller" do
    fixtures :families, :brothers
    set_controller_name :families

    helper :make_brother do |name|
      Brother.new :name => name, :age => 21, :family => family(:smith)
    end

    specify "should add a brother" end
      family(:smith).should.have(3).brothers

      # posts to the FamiliesController, action 'add_brother'
      post 'add_brother', :family => 'smith', :name => 'Jim', :age => 21

      response.should.be.success
      assigns('brother').should.equal make_brother('Jim')

      family(:smith).should.have(4).brothers
    end
  end

By:

Lachie Cox, http://lachie.info

With valuable contributions and feedback from: Chad Nantais,

many thanks to the RSpec team http://rspec.rubyforge.org/

thanks to Zenspider: Some code in the Controller mixin is lifted from zenspider’s Test::Unit::Rails http://www.zenspider.com/ZSS/Products/ZenTest/index.html

thanks to the Rails team http://rubyonrails.org

Vitals

Repository http://lachie.info/svn/projects/rails_plugins/rspec_on_rails/
License
Rating (29 votes)
Owner Lachie Cox
Created 9 June 2006

Comments

  • Avatar
    max williams
    31 January 2008

    Hi Lachie- the repository address doesn't work for me, i get a 'plugin not found' error. Am i doing something wrong?

    thanks

  • Avatar
    max williams
    31 January 2008

    Hi Lachie- the repository address doesn't work for me, i get a 'plugin not found' error. Am i doing something wrong?

    thanks

  • Avatar
    Carlos OKieffe
    17 February 2008

    I recommend you look at the installation on the newer Rspec site: http://rspec.info/documentation/rails/install.html

  • Avatar
    21 June 2008

    I am experiencing the same problem that max had, and then I wen to the newer site and get a beautiful default rails 404 error message. So go here to get the instructions on rspec for rails. http://github.com/dchelimsky/rspec-rails/wikis/home

  • Avatar
    snowmaninthesun
    25 June 2008

    http://github.com/dchelimsky/rspec-rails/wikis/home

    Plugin not found: for any of the repository locations listed, i'm tring to install restful authentication, can i do it without rspec on rails??

  • bolek
    9 December 2008

    Same for me

Add a comment