Git Product home page Git Product logo

rspec-rails's Introduction

rspec-rails-2

RSpec-2 for Rails-3

rspec-rails-2 brings rspec-2 to rails-3 with lightweight extensions to both libraries.

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.

Living on edge

If you prefer to exploit bundler's support for pointing a gem at a github repo, be sure to do so for all five of the relevant rspec gems:

gem "rspec-rails",        :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec",              :git => "git://github.com/rspec/rspec.git"
gem "rspec-core",         :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks",        :git => "git://github.com/rspec/rspec-mocks.git"

Keep in mind that each of these repos is under active development, which means that its very likely that you'll pull from these repos and they won't play nice together. If playing nice is important to you, stick to the published gems.

Backwards compatibility

This is a complete 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. Many of the APIs from rspec-rails-1 have been carried forward, however, so upgrading an app from rspec-1/rails-2, while not pain-free, should not send you to the doctor with a migraine.

Synopsis

  • 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
  • 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
  • webrat matchers
  • generators
    • run "script/rails g" to see the list of available generators

Known issues

  • no helper specs (yet)
  • no routing specs (yet)
  • only works with ActiveRecord (for now)

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.

rendering views

By default, controller specs do not render views (as of beta.9). This supports specifying controllers without concern for whether the views they render work correctly or even exist. If you prefer to render the views (a la Rails' functional tests), you can use the render_views declaration in each example group:

describe SomeController do
  render_views
  ...

Matchers

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

render_template

Delegates to Rails' assert_template:

response.should render_template("new")

redirect_to

Delegates to assert_redirect

response.should redirect_to(widgets_path)

rspec-rails's People

Contributors

dchelimsky avatar hasimo avatar wycats avatar kristianmandrup avatar bjreath avatar iain avatar ion1 avatar ku1ik avatar njackson avatar novroy avatar speedmax avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.